| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4091 人关注过本帖
标题:求教给位大神,VS2013代码中使用printf之类的不需要加stdio.h否则会报错,但 ...
取消只看楼主 加入收藏
swt2012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
求教给位大神,VS2013代码中使用printf之类的不需要加stdio.h否则会报错,但是不加的话FILE *fp又不能用(报错),怎么办?
VS2013代码中使用printf之类的不需要加stdio.h否则会报错,但是不加的话FILE *fp又不能用(报错),怎么办?

程序代码:
#include"func.h"

main()          /**主函数**/
{
    printf("\n\n\n\t\t~~~~~~~~~~~~~~~~酒店管理系统~~~~~~~~~~~~~~~~~");
    printf("\n\n\n\t\t\tPress any key to continue.....");
    printf("\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t---By黄李\n");
    getch();
    menu();
}

void regist()             /**注册函数**/
{
    int n, m, i, j;
    printf("\tHow many new customs?\t"); scanf("%d", &n);
    printf("\tHow many rooms they want?  "); scanf("%d", &m);
    for (i = r; i<r + m; i++)

    {
        {puts("\n\tRoom_ID:\t"); scanf("%d", &room[i].room_ID);
        puts("\n\tTel:\t"); scanf("%s", room[i].tel);
        puts("\n\tPrice:\t"); scanf("%d", &room[i].price);
        room[i].sign = 1;
        }
        for (j = p; j<p + n; j++)
        {
            puts("\n\tName:\t"); scanf("%s", room[i].client_list[j].name);
            puts("\n\tSex(1 for men || 0 for women):\t"); scanf("%d", &room[i].client_list[j].sex);
            puts("\n\tAge:\t"); scanf("%d", &room[i].client_list[j].age);
            puts("\n\tID_card:\t"); scanf("%s", room[i].client_list[j].ID_card);
            puts("\n\tYear:\t"); scanf("%d", &room[i].client_list[j].year);
            puts("\n\tMonth:\t"); scanf("%d", &room[i].client_list[j].month);
            puts("\n\tDate:\t"); scanf("%d", &room[i].client_list[j].date);
        }
    }
    r = r + m;
    p = p + n;
    save();
    menu();
}

void menu()                    /*****菜单函数*****/
{
    int n, w;
    do
    {
        puts("\n\n\n\t***************************MENU*****************************\n\n");
        puts("\t\t\t  ||(1).Regist    ||\n");
        puts("\t\t\t  ||(2).Statistics||\n");
        puts("\t\t\t  ||(3).Search    ||\n");
        puts("\t\t\t  ||(4).Modify    ||\n");
        puts("\t\t\t  ||(5).Exit      ||\n");
        puts("\n\t***********************************************************\n");
        printf("\t\tPlease choice you number(1-5)");
        scanf("%d", &n);
        if (n<1 || n>5) w = 1, getchar();
        else w = 0;
    } while (w == 1);
    switch (n)
    {
    case 1:regist(); break;
    case 2:stat(); break;
    case 3:search(); break;
    case 4:modify(); break;
    case 5:exit(0);
    }
}


void stat()        /***统计函数***/
{
    int n, m;
    do
    {
        puts("\t\t*********************MENU************************\n");
        puts("\t\t\t\t1).Statistics one month\n");
        puts("\t\t\t\t2).Statistics using room\n");
        puts("\t\t\t\t3).MENU()");
        puts("\t\t**************************************************\n");
        printf("\t\tPlease choice your number(1-3):[ ]\b\b");
        scanf("%d", &n);
        if (n<1 && n>3)
        {
            m = 1;
            getchar();
        }
        else m = 0;
    } while (m == 1);
    switch (n)
    {
    case 1:stat_o(); break;
    case 2:stat_u(); break;
    case 3:menu();
    }
}

void stat_o()           /*******统计人数******/
{
    int j, i, n, l;
    int s = 0;
    puts("Please input the month you want to statistics:"); scanf("%d", &n);
    load_room();
    for (i = 0; i<r; i++)
        for (j = 0; j<p; j++)
            if (room[i].client_list[j].month == n) s = s + 1;
    printf("There are %d customer this month", s);
    puts("\n\nWhat you want to do?\n");
    puts("1).Statistics again\t2).back\n");
    scanf("%d", &l);
    switch (l)
    {
    case 1:stat_o(); break;
    case 2:stat();
    }
}


void stat_u()    /******统计使用中的房间*****/
{
    int j, l, s = 0;
    load_room();
    for (j = 0; j<p; j++)
    {
        if (room[j].sign == 1) s += 1;
    }
    printf("There are %d rooms in use", s);
    puts("\n\nWhat you want to do?\n");
    puts("1).Statistics again\t2).back\n");
    scanf("%d", &l);
    switch (l)
    {
    case 1:stat_u(); break;
    case 2:stat();
    }
}

printf_p(int i, int j)               /******显示个人信息******/
{
    printf("name:"); puts(room[i].client_list[j].name);
    printf("\nsex:%d\n", room[i].client_list[j].sex);
    printf("\nage:%d\n", room[i].client_list[j].age);
    puts("\nID_card:"); printf("%s", room[i].client_list[j].ID_card);
    printf("\nyear:%d\n", room[i].client_list[j].year);
    printf("\nmonth:%d\n", room[i].client_list[j].month);
    printf("\ndate:%d\n", room[i].client_list[j].date);
    printf("\nRoom_ID:%d\n", room[i].room_ID);
    printf("\nTel:%s\n", room[i].tel);
    printf("\nPrice:%d\n", room[i].price);
}

void search()  /********查找函数********/
{
    int n, m;
    do
    {
        puts("\n\n\t\t*********************MENU************************\n");
        puts("\t\t1).Search someone had erev lived here\n");
        puts("\t\t2).Search someday \n");
        puts("\t\t3).MENU()");
        puts("\t\t************************************************\n");
        printf("\t\tPlease choice your number(1-3):[ ]\b\b");
        scanf("%d", &n);
        if (n<1 && n>3)
        {
            m = 1;
            getchar();
        }
        else m = 0;
    } while (m == 1);
    switch (n)
    {
    case 1:search_one(); break;
    case 2:search_day(); break;
    case 3:menu();
    }
}

void search_one()       /*****查找个人*****/
{
    int i, j, w = 0, l, m, n;
    char s[20];
    printf("Please input the name\n");
    scanf("%s", s);
    load_room();
    for (i = 0; i<r; i++)
        for (j = 0; j<p; j++)
            if (strcmp(room[i].client_list[j].name, s) == 0) w = 1, m = i, n = j;
    if (w == 1)
        printf_p(m, n);
    else printf("\nThere is no record here\n");
    puts("What do you want to do?\n");
    puts("1).search again\t2).back\n");
    scanf("%d", &l);
    switch (l)
    {
    case 1:search_one(); break;
    case 2:search();
    }
}

void search_day()          /*******查询某日的使用情况*******/
{
    int i, j, l, m, n, a, b, c, w = 0;
    printf("\nPlease input the day you want to search");
    printf("\nYear:"); scanf("%d", &a);
    printf("\nMonth:"); scanf("%d", &b);
    printf("\nDate:"); scanf("%d", &c);
    load_room();
    for (i = 0; i<p; i++)
        for (j = 0; j<r; j++)
            if ((room[i].client_list[j].date == c) && (room[i].client_list[j].month == b) && (room[i].client_list[j].year == a)) w = 1, m = i, n = j, printf_p(m, n);
    if (w == 0)
        printf("NO record this day\n");
    puts("What you want to do?\n");
    puts("1).search again\t2).back\n");
    scanf("%d", &l);
    switch (l)
    {
    case 1:search_day(); break;
    case 2:search();
    }
}

void modify()        /*****  修改函数  ******/
{
    int n, m;
    do
    {
        puts("\t\t*********************MENU************************\n");
        puts("\t\t\t\t1).modify one people\n");
        puts("\t\t\t\t2).modify one day\n");
        puts("\t\t\t\t3).MENU()");
        puts("\t\t**************************************************\n");
        printf("\t\tPlease choice your number(1-3):[ ]\b\b");
        scanf("%d", &n);
        if (n<1 && n>3)
        {
            m = 1;
            getchar();
        }
        else m = 0;
    } while (m == 1);
    switch (n)
    {
    case 1:modify_one(); break;
    case 2:modify_day(); break;
    case 3:menu();
    }
}


void modify_one()       /*****修改个人信息*****/
{
    int i, j, m, n, w = 0, l;
    char s[20];
    puts("\t\tPlease input the name");
    scanf("%s", s);
    load_room();
    for (i = 0; i<r; i++)
        for (j = 0; j<p; j++)
            if (strcmp(room[i].client_list[j].name, s) == 0) w = 1, m = i, n = j;
    if (w == 1)
        printf_p(m, n);
    else printf("\nThere is no record here\n");
    modify_s(m, n);
    save();
    puts("What you want to do?\n");
    puts("1).Modify again\t2).back\n");
    scanf("%d", &l);
    switch (l)
    {
    case 1:modify_one(); break;
    case 2:modify();
    }
}


void modify_s(int i, int j)   /*********修改执行项*********/
{
    int a, q;
    char s[20], b[15];
    printf("\nChoice the title you want to modify\n");
    puts("1).Name 2).sex  3).age  4)ID_card  5).year  6).month  7).date  8).room_ID  9)tel  10).price\   11).modify none\n");
    printf("Please choice your number(1-10):[ ]\b\b");
    scanf("%d", &q);
    switch (q)
    {
    case 1:          printf("Please input new name\n"); scanf("%s", s);
        strcpy(room[i].client_list[j].name, s); break;
    case 2:         printf("Please input new sex\n");
        scanf("%d", &a); room[i].client_list[j].sex = a; break;
    case 3:         printf("Please input the new age\n");
        scanf("%d", &a); room[i].client_list[j].age = a; break;
    case 4:         printf("Please input new ID_card\n");
        scanf("%s", s); strcpy(room[i].client_list[j].ID_card, s); break;
    case5:          printf("Please input new year\n");
        scanf("%d", &a); room[i].client_list[j].year = a; break;
    case6:  printf("Please input the new month\n"); scanf("%d", &a); room[i].client_list[j].month = a; break;
    case7:         printf("Please input the new date\n");
        scanf("%d", &a); room[i].client_list[j].date = a; break;
    case8:          printf("Please input the new room_ID\n");
        scanf("%d", &a); room[i].room_ID = a; break;
    case9: printf("Please input the new tel\n"); scanf("%s", b); strcpy(room[i].tel, b); break;
    case 10:       printf("Please input the new price\n");
        scanf("%d", &a); room[i].price = a; break;
    case 11:      modify();
    }
}

void modify_day()    /*******修改某日信息******/
{
    int i, j, l, a, b, c, w = 0, m, n;
    puts("\t\tPlease input the date");
    puts("\nYear:"); scanf("%d", &a);
    puts("\nMonth:"); scanf("%d", &b);
    puts("\nDate:"); scanf("%d", &c);
    load_room();
    for (i = 0; i<p; i++)
        for (j = 0; j<r; j++)
            if ((room[i].client_list[j].date == c) && (room[i].client_list[j].month == b) && (room[i].client_list[j].year == a)) w = 1, m = i, n = j;
    if (w == 1)
        printf_p(m, n);
    else printf("NO record this day\n");
    modify_s(m, n);
    save();
    puts("What you want to do?\n");
    puts("1).modify again\t2).back\n");
    scanf("%d", &l);
    switch (l)
    {
    case 1:modify_day(); break;
    case 2:menu();
    }
}

void save()    /********保存函数********/
{
    FILE*fp;
    int i, j;
    if ((fp = fopen("room.txt", "w")) == NULL)
    {
        printf("\nCannot open file\n");
        return NULL;
    }
    for (i = 0; i<r; i++)
        for (j = 0; j<p; j++)
            fprintf(fp, "%d,%s,%d,%d,%s,%d,%d,%s,%d,%d,%d", room[i].room_ID, room[i].tel, room[i].price, room[i].sign, room[i].client_list[j].name, room[i].client_list[j].sex, room[i].client_list[j].age, room[i].client_list[j].ID_card, room[i].client_list[j].year, room[i].client_list[j].month, room[i].client_list[j].date);
    fclose(fp);
    return 1;
}

void load_room()               /******加载函数******/
{
    FILE *fp;
    struct hotel room[N];
    int i, j;
    if ((fp = fopen("room.txt", "r")) == NULL)
    {
        printf("\nCannot open file\n");
        return 0;
    }
    for (i = 0; !feof(fp); i++)
        for (j = 0; !feof(fp); j++)
            fscanf(fp, "%d,%s,%d,%d,%s,%d,%d,%s,%d,%d,%d", &room[i].room_ID, room[i].tel, &room[i].price, &room[i].sign, room[i].client_list[j].name, &room[i].client_list[j].sex, &room[i].client_list[j].age, room[i].client_list[j].ID_card, &room[i].client_list[j].year, &room[i].client_list[j].month, &room[i].client_list[j].date);
    fclose(fp);
    r = i;
    p = j;
}

void printf_back()
{
    int k, w;
    void browse();
    printf("\n\n\tSuccessful^-^.\n\n");
    printf("What do you want to do?\n\n\t1).Browse all now\t2).Back: [ ]\b\b");
    scanf("%d", &w);
    if (w == 1)browse();
    else menu();
}
图片附件: 游客没有浏览图片的权限,请 登录注册

2016-01-08 13:33
swt2012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-8
收藏
得分:0 
回复 2楼 wp231957
对,我就是想问这个,不好意思没描述清楚。初学者,是不太会使用,能告诉我有什么办法解决一下么?
2016-01-08 14:04
swt2012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-8
收藏
得分:0 
回复 4楼 wp231957

天哪,你真好,先谢谢你,这个就是工程的压缩包。。。
ConsoleApplication22.zip (649.56 KB)
2016-01-08 14:19
快速回复:求教给位大神,VS2013代码中使用printf之类的不需要加stdio.h否则会报 ...
数据加载中...
 
   



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

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