J
jza
I once had a program which would get a directory name in argv[1] and append
"/thumbmap.txt" after it. I couldn't get it to work because when defining some
variables there would appear some garbage in the file name. Already made a
workaround for it, but I still wonder why this does not work as expected.
So, in the following code if I do not define variables cellx .. cgy the program
works fine, but with them defined the file name gets messed up. I wonder why?
Tested under Linux with gcc.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]){
char*tmap;
char*thumbmap;
char*themos;
char*small;
char*sortedf;
unsigned long*matrix;
unsigned long long tmaplen;
unsigned long long gopointer;
int mosx,mosy;
unsigned int cellx,celly;
unsigned int smallx,smally;
unsigned int cgx,cgy;
unsigned long cgt;
char sortedfb[23];
unsigned char sortedlen=0;
char sortedserial[9];
unsigned int ddlen=0;
FILE*th;
tmap=(char*)malloc(strnlen(argv[1])+14);
if(tmap==NULL){
printf("Out of memory.\n");
return 1;
}
strcpy(tmap,argv[1]);
strcat(tmap,"/thumbmap.txt");
printf("tmap is %s\n",tmap);
th=fopen(tmap,"r");
if(th==NULL){
printf("Unable to open %s\n",tmap);
return 1;
}
printf("Opened %s\n",tmap);
free(tmap);
fclose(th);
return 0;
}
"/thumbmap.txt" after it. I couldn't get it to work because when defining some
variables there would appear some garbage in the file name. Already made a
workaround for it, but I still wonder why this does not work as expected.
So, in the following code if I do not define variables cellx .. cgy the program
works fine, but with them defined the file name gets messed up. I wonder why?
Tested under Linux with gcc.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]){
char*tmap;
char*thumbmap;
char*themos;
char*small;
char*sortedf;
unsigned long*matrix;
unsigned long long tmaplen;
unsigned long long gopointer;
int mosx,mosy;
unsigned int cellx,celly;
unsigned int smallx,smally;
unsigned int cgx,cgy;
unsigned long cgt;
char sortedfb[23];
unsigned char sortedlen=0;
char sortedserial[9];
unsigned int ddlen=0;
FILE*th;
tmap=(char*)malloc(strnlen(argv[1])+14);
if(tmap==NULL){
printf("Out of memory.\n");
return 1;
}
strcpy(tmap,argv[1]);
strcat(tmap,"/thumbmap.txt");
printf("tmap is %s\n",tmap);
th=fopen(tmap,"r");
if(th==NULL){
printf("Unable to open %s\n",tmap);
return 1;
}
printf("Opened %s\n",tmap);
free(tmap);
fclose(th);
return 0;
}