一个简单的只输入和读出的通讯录程序,帮忙看看哪里错了
#include<stdio.h>#include <windows.h>
#include<windows.h>
#include<stdlib.h>
#define NUM 100
struct classmates
{
char name;
char sex;
int phone;
int QQ;
char address;
}classmates[NUM], *p;
void print()
{
int i,n=1,choose;
for (i = 0; i < NUM; i++, p++)
{
n = i;
printf("输入名字:\n");
scanf("%s", &p->name);
printf("输入性别:\n");
scanf("%s", &p->sex);
printf("电话:\n");
scanf("%d", &p->phone);
printf("输入QQ:\n");
scanf("%d", &p->QQ);
printf("输入地址:\n");
scanf("%s", &p->address);
printf("是否继续:1.继续 ;0.退出并保存; ");
scanf("%d", &choose);
if (choose == 1)
print();
else
exit(0);
}
}
int main()
{
FILE *fp;
int i,n;
p = classmates;
if ((fp = fopen("E:\\play\\classmates_list", "r+")) == NULL);
{
printf("can't create file!\n");
exit(0);
} //判断文件是否存在,是否能正常打开
void print();
for (i = 0; i < n; i++, p++)
fprintf(fp, "%s%s%d%d%s", p->name,p->sex,p->phone, p->QQ, p->address);
//输入到指定文件中
//以下为从文件中调出并打印该通讯录
rewind(fp);//返回到流开头
for (i = 0; i < n; i++, p++)
fscanf(fp, "%s%s%d%d%s", &p->name, &p->sex, &p->phone, &p->QQ, &p->address);//从文件中读入数据并赋给相应地址
for (i = 0; i < n; i++, p++)
printf("%s\n%s\n%d\n%d\n%s\n", p->name, p->sex, p->phone, p->QQ, p->address);//打印该通讯录
fclose(fp);
}
这程序我一直不能调用文件,一直显示这:"can't create file! 求教
[ 本帖最后由 traveller、z 于 2015-4-1 21:34 编辑 ]