Hi my code is as follows
char name[100] ;
_getcwd(name, (size_t)sizeOfFileName);
strcat(name,"\\") ;
strcat(name, fileName) ;
char *value_str= NULL ;
file = fopen(name, "a+");
if(!file)
printf("bad file name") ;
for(i = 0; i<fileSize ; i++)
{
value_str = fp_to_str(ddata[i]) ;
strLength= strlen(value_str) ;
value_str[strLength+1] = 10 ;
num = strlen(value_str);
count = fwrite(value_str, sizeof(char), num, file);
}
I'm having problems writing the value of value_str into the file given by file. Until it reaches the line of code containing fwrite, the value of value_str does not change. then it changes to some junk value. Can you please tell me what is wrong? SizeOfFileName is passed to the function earlier. the code works perfectly until it reaches the fwrite line of code and then its value just changes. and some junk values are written into the text file.
the function fp_to_str is my own function in the current code. it properly returns the value i want to value_str. what fp_to_str does is to convert a double number into a character array, which is stored in value_str.
once the code is done with the fwrite, it changes the correct data that is there in value_str to some garbage value.
ddata[i] takes the double number from the double array one by one and passes it into fp_to_str(). what i am trying to do is write these double numbers which are in ddata[] array into a text file.
I have commented the line to add value 10 to the end of the string. I assumed wrongly that I have to add a null character at the end of the string. I still am having the same problem. anyone know why?