Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <stdio.h>
int main ( int argc, char *argv[] ) {
int i;
for ( i = 0 ; i < argc ; i++ ) {
printf( "Arg %d = %s\n", i, argv[i] );
}
return 3;
}
$ gcc prog.c
# run the program with some command line parameters
$ ./a.out hello world, how are you today?
Arg 0 = ./a.out
Arg 1 = hello
Arg 2 = world,
Arg 3 = how
Arg 4 = are
Arg 5 = you
Arg 6 = today?
# This is the exit status of the program (the return 3; at the end of main)
# use this to pass back basic success/fail status information.
$ echo $?
3
#include <stdio.h>
int main ( int argc, char *argv[] ) {
char buff[BUFSIZ];
while ( fgets ( buff, BUFSIZ, stdin ) != NULL ) {
fputs ( buff, stdout );
}
return 0;
}
$ gcc hello.c
# read from a file, output to terminal
$ ./a.out < hello.c
#include <stdio.h>
int main ( int argc, char *argv[] ) {
char buff[BUFSIZ];
while ( fgets ( buff, BUFSIZ, stdin ) != NULL ) {
fputs ( buff, stdout );
}
return 0;
}
# read from a file, write to another file
$ ./a.out < hello.c > results.txt
# read from a file, send output to another program
$ ./a.out < hello.c | wc
8 34 176