char* output= (char*) argv[2];
92 fp = fopen(output, "w");
93 if( fp = NULL )
94 {
95 printf("writing output failed");
96 return 0;
97 }
98 fprintf(fp,"hello");
这会导致第 98 行出现段错误 exc bad memory。 我错过了什么??
最佳答案
你的线路
if( fp = NULL)
是将NULL
的值赋给fp
,而不是比较。
你应该使用
if( fp == NULL)
关于c - fprintf 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12898162/