Hi guys, this is my first post hereHope you can help me out with the problem I have...
I'm trying to create a text file with a variabe filename. My idea was to use the time from this function:
as the filename, according to this function:Code:/* time example */ #include <stdio.h> #include <time.h> int main () { time_t seconds; seconds = time (NULL); printf ("%ld hours since January 1, 1970", seconds/3600); return 0; }
Now this is what I got so far:Code:#include "stdio.h" File Input/Output C Tutorial 10-5 main( ) { FILE *fp1; char oneword[100],filename[25]; char *c; printf("enter filename -> "); scanf("%s",filename); /* read the desired filename */ fp1 = fopen(filename,"r"); do { c = fgets(oneword,100,fp1); /* get one line from the file */ if (c != NULL) printf("%s",oneword); /* display it on the monitor */ } while (c != NULL); /* repeat until NULL */ fclose(fp1); }
But when I compile this, I get the error that Im doing an "Invalid conversion from time_t to const_char.Code:FILE *stream; time_t seconds; seconds = time (NULL); stream = fopen(seconds, "w");
Has anyone got an idea how to solve this? Any help is highly appreciated, thanks in advance.
René



LinkBack URL
About LinkBacks
Hope you can help me out with the problem I have...



But yes, stay with what you had. I was just suggesting an alternative.