| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 831 人关注过本帖
标题:求大神指教,为什么VS总报错
只看楼主 加入收藏
zerahfan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2017-3-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:6 
求大神指教,为什么VS总报错
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
2017-03-01 16:05
zerahfan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2017-3-1
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
前边都定义好了啊
2017-03-01 16:08
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:10 
能不能贴代码不要贴图
2017-03-01 16:55
zerahfan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2017-3-1
收藏
得分:0 
#include "shop.h"
void main() {
    FILE*fp;
    fp = fopen("商品信息","a+");//创建商品信息文件
    fclose(fp);
    fp = fopen("清单","w+");
    fclose(fp);
    menu();
    system("pause");
}


#include<stdio.h>
#include<Windows.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100
struct product {
    long number;//商品编号
    char name[10];
    float inprice;
    float outprice;
    int count;//商品数量
};
void menu();//菜单
void in();//进库管理
void out();//出库
void add();
void del();
void sale();
void exit();


#include"shop.h"
void menu()
{
    int choice;
    system("color 3e");
    printf("0退出");
    printf("1商品进库管理");
    printf("2商品出库管理");
    printf("3创建新商品");
    printf("4删除商品");
    printf("5销售统计");
    printf("6显示库存量");
    scanf("%d", &choice);
    switch (choice)
    {
    case 0:
        Exit();
        break;
    case 1:
        In();
        break;
    case 2:
        Out();
        break;
    case 3:
        Add();
        break;
    case 4:
        Del();
        break;
    case 5:
        Sale();
        break;
    default:
        menu();

    }
}
//增加新商品
void add()
{
    FILE*fp;
    char m;
    struct product inf;
    printf("输入商品编号:\n");
    scanf("%ld", &inf.number);
    printf("输入商品数量:\n");
    scanf("%d", &inf.count);
    printf("输入商品进价:\n");
    scanf("%d", &inf.inprice);
    printf("输入商品售价:\n");
    scanf("%d", &inf.outprice);
    printf("输入商品名称:\n");
    scanf("%s", &inf.name);
    fopen("商品信息", "a+");
    if (fp == NULL)
        printf(" ");
    fwrite(&inf, sizeof(struct product), 1, fp);
    fclose(fp);
    printf("是否继续输入,是y,否n\n");
    getchar();
    m = getchar;
    if (m == 'y')
        Add();
    if (m == 'n')
        menu();
}

    //进货模块
void in()
{//1
    FILE*fp;
    int i = 0;
    int b;
    char m;
    long number;
    int count;
    struct product inf[SIZE];
    struct product inf1;

    fp = fopen("商品信息.txt", "r");
    if (fp = fopen("商品信息.txt", "r") == NULL);
    printf("打开信息文件错误");
    printf("输入产品编号\n");
    scanf("%ld", &number);
    printf("输入产品数量\n");
    scanf("%d", &count);
    while (fread(&inf1, sizeof(struct product), 1, fp) != (int)NULL);
    if (inf1.number != number)
    {
        inf[i].number = inf1.number;
        strcpe(inf[i].name, inf1.name);
        inf[i].inprice = inf1.inprice;
        inf[i].outprice = inf1.outprice;
        inf[i].count = inf1.count;
        i++;
    }
    else
    {
        inf[i].number = inf1.number;
        inf[i].inprice = inf1.inprice;
        inf[i].outprice = inf1.outprice;
        inf[i].count = inf1.count;
        i++;
    }

    fclose(fp);
    if ((fp = fopen("商品信息.txt", "w+") == NULL)
        printf("打开文件出错\n");
    for (b = 0; b < 1; b++)
    {
        if (fwrite(&inf[b], sizeof(struct produce), 1, fp) == !1)
            printf("写入商品文件错误\n");
    }
    fclose(fp);
    printf("是否继续输入,是y,否n");
    getchar()
        m = getchar;

    if (m = 'y')
        in();
    if (m = 'n')
        menu();
}
        
   
//出货模块
void out()
{
    FILE*fp;
    float money = 0;
    long number;
    int count, i, b;
    struct product inf[SIZE], inf1;
    struct product list;
    if ((fp = fopen("商品信息.txt", "rb")) == NULL)
        printf("打开文件错误\n");
    printf("请输入产品编号\n");
    scanf("%ld", &number);
    i = 0;
    while (fread(&inf1, sizeof(struct product), 1, fp) != (int)NULL);
    {
        if (inf1.number != number)
        {
            inf[i].number = inf1.number;
            strcpy(inf[i].name, inf1.name);
            inf[i].inprice = inf1.inprice;
            inf[i].outprice = inf1.outprice;
            inf[i].count = inf1.count;
            i++;
        }
        else
        {
            inf[i].number = inf1.number;
            inf[i].inprice = inf1.inprice;
            inf[i].outprice = inf1.outprice;
            inf[i].count = inf1.count;
            strcpe(inf[i].name, inf1.name);
            list.number = number;
            list.count = count;
            list.inprice = inf1.inprice;
            list.outprice = inf1.outprice;
            strcpy(list.name, inf1.name);
            money = (list.count)*(list.outprice);
            i++;
        }
    }
    fclose(fp);
    if (fp = fopen("商品信息.txt", "w+") == NULL);
    printf("打开信息文件错误");
    for (b = 0; b < i; b++)
    {
        if (fwrite(&inf[b], sizeof(struct produce), 1, fp) == !1)
            printf("写入商品文件错误\n");
    }
    fclose(fp);
    fp = fopen("清单", "a+");
    fwrite(&list, sizeof(struct product), 1, fp) == ((int)NULL);
    fclose(fp);
}
//显示库存
void remined()
{
    struct product list1;
    FILE*(fp);
    fp = fopen("商品信息.txt", "r+");
    printf("商品编号    商品名称   商品进价   商品售价  库存量");
    while (fread(&list1, sizeof(struct product), 1, fp) != (int)NULL);
    print("%ld%s%f%f  %d", list1.number, list1.name, list1.inprice, list1.outprice, list1.outprice);
    printf("按任意键返回菜单");
    getchar();
    getchar();
    menu();
}

//退出模块
void exit()
{
    char m;
    printf("是否退出程序,是y,否n");
    getchar();
    m = getchar;
    if (m == 'y')
        exit(1);
    else
        menu();
}

//删除商品模块
void del()
{
    FILE*fp;
    int i, b;
    long number;
    struct product inf[SIZE], infd;
    char m;
    printf("请输入产品编号");
    scanf("%ld", &number);
    fp = fopen("商品信息.txt", 1, "r");
    if (fp == NULL)
        printf("打开文件错误");
    i = 0;
    while (fread(&infd, sizeof(struct product), 1, fp) != (int)NULL);
    {
        if (infd.number != number)
        {
            inf[i].number = infd.number;
            inf[i].inprice = infd.inprice;
            inf[i].outprice = infd.outprice;
            inf[i].count = infd.count;
            strcpy(inf[i].name, infd.name);
            i++;
        }
    }
    fclose(fp);
    if (fopen("商品信息txt", 1, " w + ") == NULL)
        printf("打开商品信息文件错误");
    for (b = 0; b < i; b++)
    {
        if (fwrite(&inf[b], sizeof(struct product), 1, fp) == 1)
            printf("写入文件错误!");
    }
    printf("是否继续输入,是y,否n\n");
    getchar();
    m = getchar;
    if (m == 'y')
        del();
    if (m == 'n')
        menu();
}

//销售模块
void sale()
{
   
    char m;
    struct product list;
    FILE*fp;
    fp = fopen("清单", "r");
    printf("商品编号");
    while (fread(&list, sizeof(struct product), 1, fp) != NULL)
        printf("%ld %s %lf %lf", list.number, list.name, list.outprice, (list.outprice*list.count);

    printf("按任意键返回菜单\n");
    getcher();
    getcher();
    menu();
}
2017-03-01 17:00
qdcs
Rank: 6Rank: 6
等 级:侠之大者
威 望:5
帖 子:171
专家分:458
注 册:2016-12-22
收藏
得分:10 
不要贴图,没法测试,
图片附件: 游客没有浏览图片的权限,请 登录注册


我是硬件工程师
2017-03-01 17:07
qdcs
Rank: 6Rank: 6
等 级:侠之大者
威 望:5
帖 子:171
专家分:458
注 册:2016-12-22
收藏
得分:0 
程序代码:
/* Note:Your choice is C IDE

#include [color=#800000]"stdio.h"
void main()
{
   

}[/color]*/
void main()   //原void add()
{
    FILE*fp;               //fp没有指向文件商品信息
    char m;
    struct product inf;
    printf("输入商品编号:\n");
    scanf("%ld", &inf.number);
    printf("输入商品数量:\n");
    scanf("%d", &inf.count);
    printf("输入商品进价:\n");
    scanf("%d", &inf.inprice);
    printf("输入商品售价:\n");
    scanf("%d", &inf.outprice);
    printf("输入商品名称:\n");
    scanf("%s", &inf.name);
    fopen("商品信息", "a+");//fp没有指向文件商品信息
    if (fp == NULL)
        printf(" ");
    fwrite(&inf, sizeof(struct product), 1, fp); //没有给具体成员
    fclose(fp);
    printf("是否继续输入,是y,否n\n");
    getchar();
    m = getchar;
    if (m == 'y')
        Add();
    if (m == 'n')
        menu();
}
图片附件: 游客没有浏览图片的权限,请 登录注册

我是硬件工程师
2017-03-01 17:32
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
改了一些错误,还有一些得慢慢看
//#include "shop.h"


#include<stdio.h>
#include<Windows.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100
struct product {
    long number;//商品编号
    char name[10];
    float inprice;
    float outprice;
    int count;//商品数量
};
void menu();//菜单
void in();//进库管理
void out();//出库
void add();
void del();
void sale();
void exit();

void main() {
    FILE* fp;
    fp = fopen("商品信息", "a+");//创建商品信息文件
    fclose(fp);
    fp = fopen("清单", "w+");
    fclose(fp);
    menu();
    system("pause");
}

void menu()
{
    int choice;
    system("color 3e");
    printf("0退出");
    printf("1商品进库管理");
    printf("2商品出库管理");
    printf("3创建新商品");
    printf("4删除商品");
    printf("5销售统计");
    printf("6显示库存量");
    scanf("%d", &choice);
    switch (choice)
    {
    case 0:
        Exit();
        break;
    case 1:
        In();
        break;
    case 2:
        Out();
        break;
    case 3:
        Add();
        break;
    case 4:
        Del();
        break;
    case 5:
        Sale();
        break;
    default:
        menu();

    }
}
//增加新商品
void add()
{
    FILE*fp = fopen("商品信息", "a+");
    char m;
    struct product inf;
    printf("输入商品编号:\n");
    scanf("%ld", &inf.number);
    printf("输入商品数量:\n");
    scanf("%d", &inf.count);
    printf("输入商品进价:\n");
    scanf("%d", &inf.inprice);
    printf("输入商品售价:\n");
    scanf("%d", &inf.outprice);
    printf("输入商品名称:\n");
    scanf("%s", &inf.name);
    fopen("商品信息", "a+");
    if (fp == NULL)
        printf(" ");
    fwrite(&inf, sizeof(struct product), 1, fp);
    fclose(fp);
    printf("是否继续输入,是y,否n\n");
    getchar();
    m = getchar;
    if (m == 'y')
        Add();
    if (m == 'n')
        menu();
}

//进货模块
void in()
{//1
    FILE*fp;
    int i = 0;
    int b;
    char m;
    long number;
    int count;
    struct product inf[SIZE];
    struct product inf1;

    fp = fopen("商品信息.txt", "r");
    if (fp = fopen("商品信息.txt", "r") == NULL);
    printf("打开信息文件错误");
    printf("输入产品编号\n");
    scanf("%ld", &number);
    printf("输入产品数量\n");
    scanf("%d", &count);
    while (fread(&inf1, sizeof(struct product), 1, fp) != (int)NULL);
    if (inf1.number != number)
    {
        inf[i].number = inf1.number;
        strcpe(inf[i].name, inf1.name);
        inf[i].inprice = inf1.inprice;
        inf[i].outprice = inf1.outprice;
        inf[i].count = inf1.count;
        i++;
    }
    else
    {
        inf[i].number = inf1.number;
        inf[i].inprice = inf1.inprice;
        inf[i].outprice = inf1.outprice;
        inf[i].count = inf1.count;
        i++;
    }

    fclose(fp);
    if ((fp = fopen("商品信息.txt", "w+") == NULL))
        printf("打开文件出错\n");
    for (b = 0; b < 1; b++)
    {
        if (fwrite(&inf[b], sizeof(struct product), 1, fp) == !1)
            printf("写入商品文件错误\n");
    }
    fclose(fp);
    printf("是否继续输入,是y,否n");
    getchar();
        m = getchar;

    if (m = 'y')
        in();
    if (m = 'n')
        menu();
}


//出货模块
void out()
{
    FILE*fp;
    float money = 0;
    long number;
    int count, i, b;
    struct product inf[SIZE], inf1;
    struct product list;
    if ((fp = fopen("商品信息.txt", "rb")) == NULL)
        printf("打开文件错误\n");
    printf("请输入产品编号\n");
    scanf("%ld", &number);
    i = 0;
    while (fread(&inf1, sizeof(struct product), 1, fp) != (int)NULL);
    {
        if (inf1.number != number)
        {
            inf[i].number = inf1.number;
            strcpy(inf[i].name, inf1.name);
            inf[i].inprice = inf1.inprice;
            inf[i].outprice = inf1.outprice;
            inf[i].count = inf1.count;
            i++;
        }
        else
        {
            inf[i].number = inf1.number;
            inf[i].inprice = inf1.inprice;
            inf[i].outprice = inf1.outprice;
            inf[i].count = inf1.count;
            strcpe(inf[i].name, inf1.name);
            list.number = number;
            list.count--;
            list.inprice = inf1.inprice;
            list.outprice = inf1.outprice;
            strcpy(list.name, inf1.name);
            money = (list.count)*(list.outprice);
            i++;
        }
    }
    fclose(fp);
    if (fp = fopen("商品信息.txt", "w+") == NULL);
    printf("打开信息文件错误");
    for (b = 0; b < i; b++)
    {
        if (fwrite(&inf[b], sizeof(struct product), 1, fp) == !1)
            printf("写入商品文件错误\n");
    }
    fclose(fp);
    fp = fopen("清单", "a+");
    fwrite(&list, sizeof(struct product), 1, fp) == ((int)NULL);
    fclose(fp);
}
//显示库存
void remined()
{
    struct product list1;
    FILE *fp;
    fp = fopen("商品信息.txt", "r+");
    printf("商品编号    商品名称   商品进价   商品售价  库存量");
    while (fread(&list1, sizeof(struct product), 1, fp) != (int)NULL);
    print("%ld%s%f%f  %d", list1.number, list1.name, list1.inprice, list1.outprice, list1.outprice);
    printf("按任意键返回菜单");
    getchar();
    getchar();
    menu();
}

//退出模块
void exit()
{
    char m;
    printf("是否退出程序,是y,否n");
    getchar();
    m = getchar;
    if (m == 'y')
        exit(1);
    else
        menu();
}

//删除商品模块
void del()
{
    FILE*fp;
    int i, b;
    long number;
    struct product inf[SIZE], infd;
    char m;
    printf("请输入产品编号");
    scanf("%ld", &number);
    fp = fopen("商品信息.txt", 1, "r");
    if (fp == NULL)
        printf("打开文件错误");
    i = 0;
    while (fread(&infd, sizeof(struct product), 1, fp) != (int)NULL);
    {
        if (infd.number != number)
        {
            inf[i].number = infd.number;
            inf[i].inprice = infd.inprice;
            inf[i].outprice = infd.outprice;
            inf[i].count = infd.count;
            strcpy(inf[i].name, infd.name);
            i++;
        }
    }
    fclose(fp);
    if (fopen("商品信息txt", 1, " w + ") == NULL)
        printf("打开商品信息文件错误");
    for (b = 0; b < i; b++)
    {
        if (fwrite(&inf[b], sizeof(struct product), 1, fp) == 1)
            printf("写入文件错误!");
    }
    printf("是否继续输入,是y,否n\n");
    getchar();
    m = getchar;
    if (m == 'y')
        del();
    if (m == 'n')
        menu();
}

//销售模块
void sale()
{

    char m;
    struct product list;
    FILE*fp;
    fp = fopen("清单", "r");
    printf("商品编号");
    while (fread(&list, sizeof(struct product), 1, fp) != NULL)
        printf("%ld %s %lf %lf", list.number, list.name, list.outprice, (list.outprice*list.count));

    printf("按任意键返回菜单\n");
    getcher();
    getcher();
    menu();
}

[此贴子已经被作者于2017-3-2 09:35编辑过]

2017-03-02 09:17
快速回复:求大神指教,为什么VS总报错
数据加载中...
 
   



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

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