专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C语言

书上例子有有关问题

发布时间:2011-06-28 13:09:49 文章来源:www.iduyao.cn 采编人员:星星草
书上例子有问题求助!
#include<stdio.h>
#include <stdlib.h>
void main()
{FILE *fp;
 char ch,st[20];
 int i;
 struct stu
 { char name[15];
  char num[6];
  float score;
 }student;
 if((fp=fopen("file2.txt","w"))==NULL)
 { printf("this file Cannot be opened!");
  exit(1);
 }
 printf("input name:\n");
 scanf("%s",name);
 printf("input num:\n");
 scanf("%s",num);
 printf("input score:\n");
 scanf("%f",&score);
 fprintf(fp,"%s%s%7.2f\n",student.name,student.num,student.score);
fclose(fp);
if((fp=fopen("file2.txt","r"))==NULL)
{ printf("This file Cannot be opened!");
  exit(0);
}
printf("output from file:\n");
while(fscanf(fp,"%s%s%f\n",student.name,student.num,student.score)!=EOF)
printf("%s%s%7.2f\n",student.name,student.num,student.score);
fclose(fp);
}


--------------------Configuration: helloc - Win32 Debug--------------------
Compiling...
helloc.cpp
D:\VC语言\helloc\helloc.cpp(17) : error C2065: 'name' : undeclared identifier
D:\VC语言\helloc\helloc.cpp(19) : error C2065: 'num' : undeclared identifier
D:\VC语言\helloc\helloc.cpp(21) : error C2065: 'score' : undeclared identifier
执行 cl.exe 时出错.


这怎么还要定义呢?

------解决方案--------------------
探讨

printf("input name:\n");
scanf("%s",student.name);

------解决方案--------------------
要定义初始化结构体stu student,使用scanf("%s",student.name);
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: