How do I input an argument in the main?

----------C program-----------------------------
include <stdio.h>

int main( int argc, char *argv[] )
{
int i;
for( i=0; i<argc; i++ )
printf("%\n", argv[i]);
return 0;
}
I wrote the C program above 'print.c'.
Then, I compiled. (gcc -o print.o print.c)

In unix, I've tried to execute it. (./print.o)

How do I input an argument in the main?

Don't call the output print.o. print.o would be the default name for an object module. You would probably call the linked executable "print". At least that's a better choice than print.o. But "print" is also the name of a ksh built-in...

Anyway to run it with args just do...

./print arg1 arg2 arg3

And finally your format string in the printf call needs a little work. It's %s to print a string.

Try the following program. Put it in a file called "howdy.c".

#include <stdio.h>

int main( int argc, char *argv[] )
{
if (!argc)
{
printf("Missing input argument!\n");
printf("Usage: howdy %1\n");
return 1;
}

printf("Well howdy there %s! YeeHaw!!!\n", argv[1]);
return 0;
}

To do a simple compile, type "gcc howdy.c -o howdy"
After it's compiled (assuming you have no errors), give it a run similiar to the following:

./howdy DUDE

(But try substituting something other than dude...)

Thanks!
---> Kelsey