| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:要实现可选择继续输入与否,但是碰到了问题,哪位大侠能否帮忙修改一下,拜 ...
只看楼主 加入收藏
the_27th
Rank: 2
等 级:论坛游民
帖 子:29
专家分:29
注 册:2012-7-10
结帖率:60%
收藏
 问题点数:0 回复次数:1 
要实现可选择继续输入与否,但是碰到了问题,哪位大侠能否帮忙修改一下,拜托了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 1000
struct student
{
    char name[20];
    long id;
    float cn;
    float match;
    struct student *next;
};
struct student stu[1000];

void save_stu(struct student stu[])
{
    FILE *fp;
    int i;
    if((fp=fopen("D:\\student.txt","wb"))==NULL)
        {
            printf("cannot open the file\n");
            exit(0);
        }
    for(i=0;i<SIZE;i++)
    {
        if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
        {
            printf("file write error!\n");
        }
    }
    fclose(fp);
}

void record_stu(struct student stu[])
{
    int i;
    char ch;
    printf("请录入学生的信息:\n");
    printf("name       id       cn     match\n");
    ch=getchar();
    for(i=0;i<SIZE;i++)
    {
        scanf_s("%s%d%f%f\n",stu[0].name,stu[0].id,stu[0].cn,stu[0].match);
        printf("是否继续输入?y/n:");
        ch=getchar();
        ch=getchar();
    //    if(ch!='y')   //问题出现在这里,如果把这四句话屏蔽掉,就可以连续选择输入,单数dos界面会出现四个  "是否继续输入?y/n:"  提示,然后要输入y三次
    //    {             //才可以继续输入数据。如果不屏蔽,就直接出问题,不知道为什么
    //            break;
    //    }
         
    }
    save_stu(stu);//存档
    printf("已经存档!\n");
    ch=getchar();//用于返回主菜单
    ch=getchar();
}

void main()
{
    char ch;
    record_stu(stu);
    printf("please wait!\n");
    ch=getchar();//用于返回主菜单
    ch=getchar();
}
搜索更多相关主题的帖子: long next include cannot file 
2012-07-18 23:19
w995612220
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:139
专家分:313
注 册:2012-6-20
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 1000
struct student
{
    char name[20];
    long id;
    float cn;
    float match;
    struct student *next;
};
struct student stu[1000];

void save_stu(struct student stu[])
{
    FILE *fp;
    int i;
    if((fp=fopen("D:\student.txt","wb"))==NULL)   
       {
            printf("cannot open the file\n");
            exit(0);
        }
    for(i=0;i<SIZE;i++)
    {
        if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
        {
            printf("file write error!\n");
        }
    }
    fclose(fp);
}

void record_stu(struct student stu[])
{
    int i;
    char ch;
   

    for(i=0;i<SIZE;i++)
    {   
         printf("请录入学生的信息:\n");       //不合适在外面
        printf("name       id       cn     match\n");
        scanf("%s,%ld,%f,%f\n",stu[i].name,stu[i].id,stu[i].cn,stu[i].match);   //错误
 printf("是否继续输入?y/n:");
        ch=getchar();
        ch=getchar();
        if(ch!='y')  //这里的写法不是很合适。
        break;
              }

    save_stu(stu);//存档
    printf("已经存档!\n");
    ch=getchar();      //用于返回主菜单,按回车键回到主菜单
    ch=getchar();  
}

void main()
{
    char ch;
    record_stu(stu);
    printf("please wait!\n");
    ch=getchar();//用于返回主菜单,按回车键推出程序
    ch=getchar();  
}        //QQ306226716
2012-07-19 08:23
快速回复:要实现可选择继续输入与否,但是碰到了问题,哪位大侠能否帮忙修改一下 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014888 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved