[求助]文件及字符串操作
输入第一个student后,第二个ID被跳过不让输入怎么改?
#include <iostream>
using namespace std;
struct Stu
{
long ID;
int g;
};
int main()
{
char num[20],ch;
struct Stu s;
FILE *fp = fopen("test.txt","wb");
assert(fp != NULL);
do
{
cout << "ID: ";
gets(num);
s.ID = atol(num);
cout << "grades: ";
gets(num);
s.g = atoi(num);
fwrite(&s, sizeof(s), 1, fp);
cout << "another(y/n)?";
ch = getchar();
}while(ch == 'y');
fclose(fp);
}
[此贴子已经被作者于2007-9-14 11:09:17编辑过]