调试的时候没有报错,运行之后报错
我怀疑是文件函数的问题。调试的时候没有提示错误,程序可以运行到最后,但是最后VC会弹出错误对话框。提示 Debug Assertion Failed! 请问可能是什么原因造成的??
#include <iostream.h>
#include <stdio.h>
#include <string.h>
int main()
{
char *s = new char;
char *name = new char;
int count;
FILE *fp;
cout<<"please input your name"<<endl;
cin>>name;
count = strlen(name);
cout<<count<<endl;
cout<<name;
cout<<endl<<"please input your name again"<<endl;
gets(s);
fp = fopen("name", "w+");
if (!fp)
{
cerr<<"error"<<endl;
}
fwrite(s, 20, 1, fp);
fclose(fp);
fp = fopen("name", "r");
if (!fp)
{
cerr<<"the file you want to open is not exist"<<endl;
}
fread(name, 20, 1, fp);
fclose(fp);
*(name+21) = '\0';
cout<<name<<endl;
cout<<"is it OK?"<<endl;
}