strcat segmentation fault
I made a simple c program to create some files on the form sample1, sample2, sample3 ,....
I got segementation fault, I don't know why. Can anyone help me to do it using C (not C++) ? #include <stdio.h> #include <stdlib.h> int main (int argc , char *argv[]) { int i =0; FILE *fp; for (i=0 ; i< 10 ; i++) { fp = fopen (strcat("sample",i) , "wb"); fclose(fp); } } |
Quote:
Code:
int main (int argc , char *argv[]) |
Try something like this instead:
Code:
#include <stdio.h> |
And another problem that you will have is that i is an integer. You can not add an integer to a string, unless you use tronayne's solution above (sprintf).
|
Thank you all :)
|
All times are GMT -5. The time now is 12:25 PM. |