Dewaana
asked on
Wrting to a file in C
Hi
here is the code that i am trying to write or how i am trying to write into file
FILE *file
out = fopen("C:\myText.txt", "W");
fprintf(out, "Temprature");
fprintf(out, "%d\n", Voltage);
fclose(file);
but i can't get it to work, could somebody please tell me what i am doing wrong, and fix the problem for me. thanks
regards
Dewaana
here is the code that i am trying to write or how i am trying to write into file
FILE *file
out = fopen("C:\myText.txt", "W");
fprintf(out, "Temprature");
fprintf(out, "%d\n", Voltage);
fclose(file);
but i can't get it to work, could somebody please tell me what i am doing wrong, and fix the problem for me. thanks
regards
Dewaana
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much, i think that if statment did the trick :)
Dewaana
Dewaana
lol, that wasn't the problem. This was:
FILE *file;
FILE *file;
FILE *out;
out = fopen("C:\\myText.txt", "W");
fprintf(out, "Temprature");
fprintf(out, "%d\n", Voltage);
fclose(out);
out = fopen("C:\\myText.txt", "W");
fprintf(out, "Temprature");
fprintf(out, "%d\n", Voltage);
fclose(out);
then you better check if fopen was successful, and you should use wt for the access type
->
FILE* file;
if(file=fopen("c:\mytext.t
{
/* do some output */
fclose(file);
}
this should work
leflon