Hello,
What I'm trying to do is call a program with 3 parameters.
eg. myProgram ABCD input.txt output.txt
then I want to add to ABCD argument the extension .test
As you can see in my code after the functionCall the argv[2] changes value. I believe that the strcat(filename, ".test") causes the problem as the argv[2] takes the value "est" but why is this happening and how can I correct it?
Thanks
/m
Code:#include <stdio.h> #include <strings.h> void functionCall (char* filename) { strcat(filename, ".test"); FILE *file = fopen(filename, "r"); if ( file != NULL ){ //code } } int main (int argc, char * argv[]){ int i; //DEBUG: PARAMETERS BEFORE printf("\n Program %s called with %d parameters:\n", argv[0], argc-1); for (i = 1; i < argc; i++) printf("\t%s \n", argv[i]); functionCall(argv[1]); //DEBUG: PARAMETERS AFTER printf("\n Program %s called with %d parameters:\n", argv[0], argc-1); for (i = 1; i < argc; i++) printf("\t%s \n", argv[i]); return 0; }



LinkBack URL
About LinkBacks



I used malloc and it works. 