| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1490 人关注过本帖
标题:小弟一点关于sacnf_s的问题 求带老帮一下我
只看楼主 加入收藏
cuihe500
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2019-4-25
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
小弟一点关于sacnf_s的问题 求带老帮一下我
程序代码:
#include <stdio.h>
#include <windows.h>
#define LONG 2
#define WIDE 2
#define SIZE sizeof(LINK)*300
#define READNUM 2
typedef struct link {
    int num;
    char name[80];
    int year;
    struct link * next;
}LINK;
void Draw(void);
void SetCurSor(int X,int Y);
void Chice(int i);
FILE * OpenTxT(void);
LINK* ReadTxT(const FILE * fp);
// static char content[SIZE];
int main(void)
{
    FILE *fp= OpenTxT();
    if (fp != NULL)
    {
        ReadTxT(fp);
    }
    Draw();
    getchar();
    return 0;
}
void Draw(void)
{
    COORD position = { 0,0 };
    HANDLE handleout = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    position.X = LONG;
    position.Y = WIDE;
    SetConsoleCursorPosition(handleout,position);
    printf("**********************************************************");
    GetConsoleScreenBufferInfo(handleout, &csbi);
    position = csbi.dwCursorPosition;
    for (size_t i = 0; i < 10; i++)
    {
        SetConsoleCursorPosition(handleout, position);
        printf("*");
        position.Y++;
    }
    position.X = LONG;
    position.Y = WIDE+10;
    SetConsoleCursorPosition(handleout, position);
    printf("***********************************************************");
    position.X = LONG;
    position.Y = WIDE;
    SetConsoleCursorPosition(handleout, position);
    for (size_t i = 0; i < 10; i++)
    {
        position.Y++;
        SetConsoleCursorPosition(handleout, position);
        printf("*");
    }
    SetCurSor(5, 5);
    printf("1.创建新的链表    *************     2.查看全部链表");
    SetCurSor(5, 9);
    printf("3.加入项到链表中  *************     4.删除链表中的项");
    SetCurSor(0, 13);
}
void SetCurSor(int X, int Y)
{
    COORD position;
    position.X = X;
    position.Y = Y;
    HANDLE handleout = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(handleout, position);
    return;
}
FILE * OpenTxT(void)
{
    FILE * Fp;
    Fp=fopen("LinkList.txt", "r");
    if (Fp==NULL)
    {
        printf("文件打开失败!");
        fclose(Fp);
        return NULL;
    }
    else
    {
        printf("文件打开成功.");
        return Fp;
    }

}
LINK* ReadTxT(const FILE * fp)
{
    LINK*head, *prv, *correct;
    head = (LINK*)malloc(sizeof(LINK));
    int count = 0;
    while(!feof(fp))
    {
        if (fgetc(fp) == '\n')
            count++;
    }
    fseek(fp, 0L, SEEK_SET);
    if (fscanf_s(fp, "%s\t%d\n", correct->name, sizeof(char[80]), &correct->year, sizeof(int)) == READNUM)
    {
        int readnum = 1;
        prv = head;
        for (int i = 1; i <= count; i++)
        {
            correct = (LINK*)malloc(sizeof(LINK));
            correct->next = NULL;
            prv->next = correct;
            if (fscanf_s(fp, "%s\t%d\n",correct->name,sizeof(char[80]),&correct->year,sizeof(int)) == READNUM)
            {
                readnum++;
                prv = prv->next;
            }
            else
            {
                printf("第%d个读取失败!", readnum);
                break;
            }
        }
        if (readnum == count)
        {
            printf("全部读取成功!");
        }
        else
        {
            printf("一共读取%d个.", readnum);
        }
    }
    return head;
}
先贴代码 问题出现在:
    if (fscanf_s(fp, "%s\t%d\n", correct->name, sizeof(char[80]), &correct->year, sizeof(int)) == READNUM)
这一行中 VS2015一直提示引用冲突啥的 求各位带老给看下谢谢!!
搜索更多相关主题的帖子: LINK int void position printf 
2019-05-31 20:26
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:10 
sizeof(int) 是干啥用的?
2019-05-31 22:02
niuniul
Rank: 2
等 级:论坛游民
威 望:2
帖 子:56
专家分:60
注 册:2018-1-13
收藏
得分:10 
回复 2楼 rjsp
sizeof(int),是查看 int类型 是占多少个字节的。

不见满街漂亮妹,哪个归得程序员?
2019-06-01 11:47
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
回复 3楼 niuniul
我问的是
fscanf_s(fp, "%s\t%d\n", correct->name, sizeof(char[80]), &correct->year, sizeof(int))
中为什么要压入 sizeof(int) 这个参数,是 fscanf_s 要求的吗?
2019-06-03 08:43
cuihe500
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2019-4-25
收藏
得分:0 
很抱歉我因为学业比较忙没来得及回复各位 问题已经解决了 就是fprintf参数传递错误
2019-06-18 21:13
快速回复:小弟一点关于sacnf_s的问题 求带老帮一下我
数据加载中...
 
   



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

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