c语言中出现fprintf错误(中断)

#include<stdio.h>
#include<stdlib.h>
#define number 5
struct item{
int a;
char firstname[200];
char lastname[200];
int TIME;
int jizhong;
int zouleishu;
int RBI;


};
struct NAME{
struct item good;
int ADD;


};
int main(void){
FILE *fp;
char *s;
int n;
struct NAME yes[number] = {
{ { 0, "first name:", "last name:", 0, 0, 0, 0 }, 0 },
{ { 0, "first name:", "last name:", 0, 0, 0, 0 }, 0 },
{ { 0, "first name:", "last name:", 0, 0, 0, 0 }, 0 },
{ { 0, "first name:", "last name:", 0, 0, 0, 0 }, 0 },
{ { 0, "first name:", "last name:", 0, 0, 0, 0 }, 0 },
};
printf("请输入数据读或写");
if (getchar() == 'w'){
if ((fp = fopen("D:\\c执行文件txt\\搜索目录\\棒球厂.txt", "w+") == NULL)){
printf("打开文件错误!");
exit(0);
}
printf("请输入球员号:");
for (int i = 0; i < number; i++){
scanf("%d\n%s\n%s\n%d\n%d\n%d\n%d\n", &(yes[i].good.a), &(yes[i].good.firstname), &(yes[i].good.lastname), &(yes[i].good.TIME), &(yes[i].good.jizhong), &(yes[i].good.zouleishu), &(yes[i].good.RBI));

yes[i].ADD = ((yes[i].good.a) + (yes[i].good.TIME) + (yes[i].good.jizhong) + (yes[i].good.zouleishu) + (yes[i].good.RBI));

}
fprintf(fp, "%d %s %s %d %d %d %d %d\n", yes[0].good.a, yes[0].good.firstname, yes[0].good.lastname, yes[0].good.TIME, yes[0].good.jizhong, yes[0].good.zouleishu, yes[0].good.RBI, yes[0].ADD);
fprintf(fp, "%d %s %s %d %d %d %d %d\n", yes[1].good.a, yes[1].good.firstname, yes[1].good.lastname, yes[1].good.TIME, yes[1].good.jizhong, yes[1].good.zouleishu, yes[1].good.RBI, yes[1].ADD);
fprintf(fp, "%d %s %s %d %d %d %d %d\n", yes[2].good.a, yes[2].good.firstname, yes[2].good.lastname, yes[2].good.TIME, yes[2].good.jizhong, yes[2].good.zouleishu, yes[2].good.RBI, yes[2].ADD);
fprintf(fp, "%d %s %s %d %d %d %d %d\n", yes[3].good.a, yes[3].good.firstname, yes[3].good.lastname, yes[3].good.TIME, yes[3].good.jizhong, yes[3].good.zouleishu, yes[3].good.RBI, yes[3].ADD);
fprintf(fp, "%d %s %s %d %d %d %d %d\n", yes[4].good.a, yes[4].good.firstname, yes[4].good.lastname, yes[4].good.TIME, yes[4].good.jizhong, yes[4].good.zouleishu, yes[4].good.RBI, yes[4].ADD);
fclose(fp);
}


else if (getchar() == 'r'){
if ((fp = fopen("D:\\c执行文件txt\\搜索目录\\棒球厂.txt", "r+")) == NULL){
printf("打开文件错误");
exit(0);
}
printf("please input lastname:\n");
gets(s);
if (*s == "Joybat") n = 0;
else if (*s == "Marry") n = 1;
else if (*s == "Hallen") n = 2;
else if (*s == "Simth") n = 3;
else if (*s == "Jack") n = 4;




switch (n){
case 0:fscanf(fp,"%s",stdin); break;
case 1:fscanf(fp, "\n%s",stdin); break;
case 2:fscanf(fp, "\n\n%s", stdin); break;
case 3:fscanf(fp, "\n\n\n%s", stdin); break;
case 4:fscanf(fp, "\n\n\n\n%s", stdin); break;
}
fclose(fp);
}
getchar();
getchar();
getchar();
return 0;

}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值