我做了一个简单的文件读取程序,在DEV C gcc编译器中成功运行,但显示错误
Debug Assertion Failed
。
我搜了一下,12天前有人问过同样的问题,
答案表明他的错误在于声明中
if (file = fopen (name, "w+") == NULL) {
...
}
并将这两个语句分开为
file = fopen(name, "w+");
if (fp == NULL) { ...}
我的代码
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int nos = 0, noc = 0, nol = 0;
char ch;
FILE *fp;
fp = fopen("Sarju.txt", "r");
while (1)
{
ch = fgetc(fp);
if (ch == NULL)
{
printf("The file didn't opened\n");
break;
}
if (ch == EOF)
break;
noc++;
if (ch == ' ')
nos++;
if (ch == '\n')
nol++;
}
if (ch != NULL)
fclose(fp);
printf("Number of Space : %d\nNumber of Characters : %d\nNumber of lines : %d\n", nos, noc, nol);
_getch();
return 0;
} `
我的错误
调试断言失败!程序:...o 2015\Projects\Let Us C Solutions\Debug\Let Us C Solutions.exe 文件:minkerne