So this program is supposed to take the input string and break it down to each individual argument into separate lines then add ".txt" to each end of the arguments after.
For example if I prompt
./nondebugmain programming is rewarding
The program should do this:
./nondebugmain
programming
is
rewarding
./nondebugmain.txt
programming.txt
is.txt
rewarding.txt
Here's my code so far.
There seems to be an error I missed and I cannot seem to be able to find it. Any tips would be nice and helpful. Thank you in advanceCode:#include <stdio.h> #include <stdlib.h> #include <string.h> void main(int argc, char **argv) { int i; int size; char *new=NULL; // print out each command-line argument on a separate line. for(i=0;i<argc;i++) printf("Command-line argument %d: %s\n",i,argv[i]); for(i=0;i<argc;i++) new = (char*)malloc(strlen(argv[i]+5)); for(i=0;i<argc;i++) { strcpy(new,argv[i]); strcat(new,".txt"); argv[i]=*new; } // print out the arguments again for(i=0;i<argc;i++) printf("Command-line argument %d: %s\n",i,argv[i]); }![]()



LinkBack URL
About LinkBacks




