Int main () { Char * PSTRS=NULL; Gets (PSTRS); The FILE * ptest=NULL;
If ((ptest=fopen (ptest, "w"))==NULL) { Printf (" failed to open the file \ n "); Perror (" "); } The fputs (PSTRS ptest); The fclose (ptest); Ptest=NULL; Printf (" -- -. -. -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, - \ n ");
If ((ptest=fopen (ptest, "r"))==NULL) { Printf (" failed to open the file \ n "); } The fgets (PSTRS, (sizeof (ptest) - 1), ptest); Puts (PSTRS); Printf (" File: % s \ n ", a __FILE__); system("pause"); return 0; } File a new failure, is why? I see the compiler error syntax errors, Small white Europe,
CodePudding user response:
The header file doesn't contain? You must learn to see the specification compile error,
CodePudding user response:
First turn on the Char * PSTRS=NULL Change Char PSTRS [256].
Otherwise it gets (PSTRS) parameter is a null pointer, illegal memory error happens
The second If ((ptest=fopen (ptest, "w"))!=NULL) Change If ((ptest=fopen (" file path string ", "w"))!=NULL)
Otherwise the parameter is a null pointer, same fopen sure can't find the path, there will be failed to open the file
CodePudding user response:
char * PSTRS=NULL; Gets (PSTRS);
Haven't to open the file that step would be wrong, because PSTRS point to NULL, understanding of the point to NULL or problematic, NULL position is not to read not write, then into the PSTRS gets is written, so make sure there will be a period of errors, So, it's not the problem of file open, but the use of pointer errors,