SmileeTiger
Programmer
I have a silly question.. I can't figure out why the following gives me an error.
int i_NumNumbers;
char c_Num[255];// take the data as a character since it is going to be dumped into a .txt file
int i; //Loop var's
FILE *File;
File=fopen("INPUTDATA.txt", "wt"
do
{
printf("Please enter the number of numbers which you intend to perform operations on"
scanf("%i",&i_NumNumbers);
} while(i_NumNumbers <= 1);
for (i=0; i<i_NumNumbers; i++)
{
printf("\nWhat is #%i?",i );
scanf(" %s", &c_Num); //It's a string 'cause I want to handle
//Floats
printf("The number is: %s\n",c_Num);
fwrite(c_Num, sizeof(char) ,255, File);
fwrite(",", sizeof(",", 1, File);
}
fclose(File);
I keep getting junk as the output of this code.. can anyone spot my error?
I think it is due to the fact that fread is spitting out all the elements in the string to the text file.. perhaps I have to add a null on the end of the string.. is there any easy way to do this?
Smilee
int i_NumNumbers;
char c_Num[255];// take the data as a character since it is going to be dumped into a .txt file
int i; //Loop var's
FILE *File;
File=fopen("INPUTDATA.txt", "wt"
do
{
printf("Please enter the number of numbers which you intend to perform operations on"
scanf("%i",&i_NumNumbers);
} while(i_NumNumbers <= 1);
for (i=0; i<i_NumNumbers; i++)
{
printf("\nWhat is #%i?",i );
scanf(" %s", &c_Num); //It's a string 'cause I want to handle
//Floats
printf("The number is: %s\n",c_Num);
fwrite(c_Num, sizeof(char) ,255, File);
fwrite(",", sizeof(",", 1, File);
}
fclose(File);
I keep getting junk as the output of this code.. can anyone spot my error?
I think it is due to the fact that fread is spitting out all the elements in the string to the text file.. perhaps I have to add a null on the end of the string.. is there any easy way to do this?
Smilee