This example code differs from the paper version handed out in that scanf("%[$\n]", ) has been replace with the equivalent gets( ).
-- w.r.n.
/* An introductory example prepared for CS 4330 Winter 2008 W.R.Nico */ #include#include #include #include static char sccs[]="@(#)example2.c Winter 2008 W.R.Nico"; int main(int argc, char * argv[]){ char msg[] = "Hello, "; int m = 5; char inputstring[16]= ""; char cmdstring[1024]; printf("What is your name? "); gets(inputstring); printf("%u greetings for %s\n", m, inputstring); sleep(2); for(; m > 0; m--) printf("%s %s.\n", msg, inputstring); printf("And here's one more for good measure!\n"); strcpy(cmdstring, "echo "); strcat(cmdstring, msg); strcat(cmdstring, inputstring); system(cmdstring); return 0; }