bob said:
Thanks for all the replies. Here's the Hello World program you asked
for:
#include <stdio.h>
main()
{
printf("Hello, world!");
return 0;
}
Well, lots of people have bombarded you with comments about this already, so
I won't add to their number. (See how much juice they squeezed from it?)
I hope the exercise gave you some idea of the sorts of problems that can
arise from an informal approach to the language (which is not to say there
aren't problems with the formal approach too). I must admit you surprised
me by remembering to return 0 from main - well done.
Your next task, should you choose to accept it, is to think up your own
project. Let's not make this too complicated - I recommend some kind of
text-filtering program, as these are very easy to do and can be useful
additions to your toolbox. Here are some possibilities:
Exercise BOB2: write a correct C program to display the first n lines of
input. (Easy)
Exercise BOB3: write a correct C program to display the leftmost n
characters of each line of input. (Easy)
Exercise BOB4: write a correct C program to display the *last* n lines of
input. (Harder.)
Exercise BOB5: write a correct C program to display the *rightmost* n
characters of each line of input. (Harder.)
(In all the above exercises, make n configurable via the command line.)
Exercise BOB6: write a correct C program to replace all occurrences in the
input of the string argv[1] with the string argv[2]. (Pretty hard.) Make
sure your user supplies a sufficient number of arguments, and complain if
he doesn't.
I'm not suggesting you write all the above, but try at least some of them.
Look for commonality between your solutions. Are there any parts you could
usefully abstract into a separate library, so that they only need be
written once?