Hello every body
how i can convert array type :
char f[12] ;
to the follwoing type :
char *f ;
because i want to use string saved in f[12] in the follwoing instruction :
fopen(char *f,mode)
Thaaaaaaaanks
Nada
Hello every body
how i can convert array type :
char f[12] ;
to the follwoing type :
char *f ;
because i want to use string saved in f[12] in the follwoing instruction :
fopen(char *f,mode)
Thaaaaaaaanks
Nada
When passing an array to a function, either array notation or pointer notation can be used
void function(char *f);
void function(char f[]);
are the same, but only in the context of function calls.
Thanks for reply
i try the code it doesn't work
It should give you an error or a warning then, if it does then post that. I'm not sure, but I think fopen may require a string constant, not an array. That could also be the problem, the only calls to fopen that I've seen have looked like this:
Code:FILE *f; f = fopen("filename.ext", "r");
Hello ,
Thank you .Your code is correct
FILE *f;
f = fopen("filename.ext", "r");
but my problem is : i need fopen not only work with filename.txt .What i need is at run time fopen take filenames automtically from text file or from certain directry then deal with it
therefore , when i write :
char fileName[20] ;
fopen(fileName,"r");
at compilation there is no problem
but at run time i get :
segmantation fault .WHY !!!!!!
Pleeease i need support
That should be fine.
Segmentation fault could really mean just about anything when it comes to problems in your program.
Is fileName null terminated? Try doing something like this:
and pepper DEBUG_PRINT inside the main function. The error will be right after the last DEBUG_PRINT that shows and the next DEBUG_PRINT in the source. Scatter inside other functions as needed.Code:#define DEBUG_PRINT { \ printf("I'm still working...\n"); \ fflush(stdout); }
BTW, fflush(stdout) might not be in <stdin.h> depending on the system, you can eliminate it in that case, it should still work OK.
.sect signature