Originally Posted by
King Mir
If marlaFC resolved this it how I think, then there's a memory leak, but under the circumstances an acceptable one.
This is what I did. So I still have a memory leak (though I don't understand it) but it's an acceptable one? Any other better ideas?
This is what I did and it works now. So are you saying that I still have a memory leak? Any other better ideas or it's fine like this?
Code:
#include <stdio.h>
#include <strings.h>
void functionCall (char* filename) {
char *dst;
char ext[] = ".test";
dst = (char *)malloc(strlen(filename)+strlen(ext));
strcpy(dst, filename);
strcat(dst, ext);
FILE *file = fopen(dst, "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;
}