标题:小弟一点关于sacnf_s的问题 求带老帮一下我
取消只看楼主
cuihe500
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2019-4-25
结帖率:0
已结贴  问题点数:20 回复次数:1 
小弟一点关于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
cuihe500
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2019-4-25
得分:0 
很抱歉我因为学业比较忙没来得及回复各位 问题已经解决了 就是fprintf参数传递错误
2019-06-18 21:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-495029-1-1.html




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

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