c program - command line prompt - need help

21 views
Skip to first unread message

raeiko

unread,
Mar 1, 2009, 6:04:37 PM3/1/09
to C/C++ Users' Group
Hello guys,

i urgently need your help

I have to write a C program that reads a series of strings and prints
only those that end with the letters “ed.” To enter the string i
should use the command line prompt and when i press the return key,
the program should print the string if it ends in "ed" and prompt for
another string if it doesn't.

My problem is that, even after reading from Dietel book and searching
in internet, I didn't get how to use the command line prompt...

Could you be so kind to give me some hints to start from?

Thanks in advance for your help,

Sai

unread,
Mar 2, 2009, 5:21:55 AM3/2/09
to C/C++ Users' Group
int main( int argc, char *argv[] )

argc will contain the number of command line parameters (including the
file name), argv[] contains the (C-string) parameters.

When you run your program (say foo) as:

./foo abc def ghi
then,

argc = 4
argv[0] = "foo"
argv[1] = "abc"
argv[2] = "def"
argv[3] = "ghi"
Reply all
Reply to author
Forward
0 new messages