| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4089 人关注过本帖
标题:求教给位大神,VS2013代码中使用printf之类的不需要加stdio.h否则会报错,但 ...
只看楼主 加入收藏
swt2012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:8 
求教给位大神,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
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
你的意思很模糊  需要去猜  

你是不是想说    我想使用printf函数 但是不能引用stdio.h 如果引用会报错
               我还想使用FILE *fp 来定义文件指针 而这个FILE类型 又貌似在stdio.h中  
导致前后矛盾???????????

可以肯定的告诉你  不存在这个现象   估计是你工程模式有问题  换句话说 vs基本使用不正确

DO IT YOURSELF !
2016-01-08 13:38
swt2012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-8
收藏
得分:0 
回复 2楼 wp231957
对,我就是想问这个,不好意思没描述清楚。初学者,是不太会使用,能告诉我有什么办法解决一下么?
2016-01-08 14:04
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
谁知道你是咋弄的啊  不然你就把工程打包发出来  我帮你看一下

DO IT YOURSELF !
2016-01-08 14:10
swt2012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-1-8
收藏
得分:0 
回复 4楼 wp231957

天哪,你真好,先谢谢你,这个就是工程的压缩包。。。
ConsoleApplication22.zip (649.56 KB)
2016-01-08 14:19
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:5 
既沒include stdio,也沒include iostream,都不知道你問的問題跟貼出來的有什麽關係,沒include,不報這些該報什麽?

授人以渔,不授人以鱼。
2016-01-08 16:26
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:5 
回复 5楼 swt2012
你的vs 版本太高   我打不开项目文件   你自己研究吧

DO IT YOURSELF !
2016-01-09 08:15
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
收藏
得分:5 
经查验,缺少browse函数,简单注释掉后编译通过,好多warning,对于我这种有强迫症的是不能容忍的,我一定要消灭所有warning,运行效果图如下(VS2010):
图片附件: 游客没有浏览图片的权限,请 登录注册



[此贴子已经被作者于2016-1-9 09:02编辑过]


能编个毛线衣吗?
2016-01-09 09:00
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1745
专家分:3216
注 册:2015-12-2
收藏
得分:5 
browse函数是什么函数?我的程序也存在这个问题,在vc中编译很好到vs中就出一大堆问题,应该选什么项目?
2016-01-09 10:29
快速回复:求教给位大神,VS2013代码中使用printf之类的不需要加stdio.h否则会报 ...
数据加载中...
 
   



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

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