Code:
#include <stdio.h>
int logfile();
int main(){
FILE * ptr;
ptr=fopen("C:\\IN.txt", "w");
fprintf(ptr, "& START ");
logfile();
getchar();
getchar();
}
int logfile(){
FILE *ptr;
ptr=fopen("C:\\IN.txt", "w");
fprintf(ptr, " goes &START\n ");
}
You are opening C:\IN.txt twice. You do not need to open it the second time. And you dont need to declare *ptr again. Logfile doesn't return an int. You have it declared as returning an int but then it never returns anything. Try this-
Code:
#include <stdio.h>
void logfile(FILE *fp);
int main(){
FILE *ptr;
ptr=fopen("C:\\IN.txt","w");
fprintf(ptr,"& START");
logfile(ptr);
getchar();
getchar();
}
void logfile(FILE *fp){
fprintf(fp," goes & START\n");
}
I just didn't declare logfile as returning an int and made it take a file pointer as an argument. It takes that file handle and prints into it.
It works fine for me but I am using Dev-C++. Try it on MSVC++ though.
~Sven