RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1558375
Accepted
justSMTH
justSMTH
Asked:2023-12-22 00:46:40 +0000 UTC2023-12-22 00:46:40 +0000 UTC 2023-12-22 00:46:40 +0000 UTC

为什么我开始在所有具有结构的行上收到错误?

  • 772

我有一个包含完全工作代码的文件,而我正在另一个文件中工作。在这两个文件中的某个时刻,代码开始抱怨所有结构。首先,我删除了新文件(那里没有做太多事情),但这没有帮助。这些文件不会相互交互。一般来说,VS 仅对那些调用结构的行给出错误。这是代码,其中

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <stdio.h>
#define MAX_SIZE_OF_MATRIX 3
#define MAX_SIZE_OF_VAL 4
typedef struct STR {
    int Val;
    int Row;
    STR* Next;
} STR;
typedef struct ListSTR {
    STR* row;
    struct ListSTR* Next;
} ListSTR;
void Add(STR** point, int Val, int Row) {
    STR* t = malloc(sizeof(STR));
    t->Row = Row;
    t->Val = Val;
    t->Next = NULL;
    STR** p = point;
    if (*p)
        for (p = &(*p)->Next; *p; p = &(*p)->Next);
    *p = t;
}
void AddToIndex(ListSTR** matrix, int index, int Val, int Row) {
    ListSTR** result = matrix;
    for (int i = 1; i <= index; i++) {
        if (*result) {
            result = &(*result)->Next;
        }
        else {
            printf("Error");
            exit(1);
        }
    }
    Add(&((*result)->row), Val, Row);
}
void clean(ListSTR* matrix, int ROWS) {
    ListSTR* matrixTemp;
    for (int i = 0; i < ROWS; i++) {
        matrixTemp = matrix;
        STR* point = matrixTemp->row;
        STR* pTemp;
        while (point) {
            pTemp = point;
            if (point->Next) {
                point = point->Next;
            }
            else {
                free(pTemp);
                break;
            }
            free(pTemp);
        }
        if (matrix->Next) {
            matrix = matrix->Next;
        }
        else {
            free(matrixTemp);
            break;
        }
        free(matrixTemp);
    }
}
int isNum(char c) {
    switch (c) {
    case '1':
        return 1;
    case '2':
        return 1;
    case '3':
        return 1;
    case '4':
        return 1;
    case '5':
        return 1;
    case '6':
        return 1;
    case '7':
        return 1;
    case '8':
        return 1;
    case '9':
        return 1;
    case '0':
        return 1;
    default:
        return 0;
    }
}
int isWhitespace(char c) {
    switch (c) {
    case' ':
        return 1;
    case'\n':
        return 1;
    case'\0':
        return 1;
    default:
        return 0;
    }
}
void GetRowsAndColums(char* filename, int* ROWS, int* COLUMNS) {
    FILE* fp = fopen(filename, "r");
    char rows[MAX_SIZE_OF_MATRIX];
    char c;
    while (isWhitespace(c = getc(fp))) {}
    int i = 0;
    while (1) {
        i = 0;
        if (isNum(c)) {
            rows[i++] = c; rows[i] = 0;
        }
        else if (isWhitespace(c)) {
            if (c == '\n') {
                printf("Error");
                exit(1);
            }
            *ROWS = strtol(rows, NULL, 10);
            break;
        }
        else {
            printf("Error");
            exit(1);
        }
        c = getc(fp);
    }
    while (isWhitespace(c = getc(fp))) {}
    char column[MAX_SIZE_OF_MATRIX];
    i = 0;
    while (1) {
        i = 0;
        if (isNum(c)) {
            column[i++] = c;  column[i] = 0;
        }
        else if (isWhitespace(c)) {
            *COLUMNS = strtol(column, NULL, 10);
            break;
        }
        else {
            printf("Error");
            exit(1);
        }
        c = getc(fp);
    }
    fclose(fp);
}
void TestAdd(ListSTR* matrix) {
    for (int i = 0; i < 3; i++) {
        matrix->row = (STR*)malloc(sizeof(STR));
        matrix->row->Row = i;
        matrix->row->Val = i + 1;
        matrix->row->Next = NULL;
        matrix = matrix->Next;
    }
}
void printMatrix(ListSTR* matrix, int ROWS, int COLUMNS) {
    STR* point;
    for (int i = 0; i < ROWS; i++) {
        point = matrix->row;
        int lastRow = -1;
        for (int j = 0; j < COLUMNS; j++) {
            if (point == NULL) {
                for (int k = 1; k < COLUMNS - lastRow; k++) {
                    printf("0 ");
                }
                break;
            }
            int Val = point->Val;
            int Row = point->Row;
            if (Row == 0) {
                printf("%d ", Val);
                lastRow = 0;
            }
            else if (Row >= COLUMNS) {
                printf("Error");
                exit(1);
            }
            else if (Row > lastRow) {
                for (int k = lastRow + 1; k < Row; k++) {
                    printf("0 ");
                }
                printf("%d ", Val);
                lastRow = Row;
            }
            else if (Row <= lastRow) {
                printf("Error");
                exit(1);
            }
            else {
                printf("%d ", Val);
            }
            point = point->Next;
        }
        printf("\n");
        matrix = matrix->Next;
    }
}
void Initialize(ListSTR* matrix, int ROWS) {
    if (ROWS == 1) {
        matrix->row = NULL;
        return;
    }
    else if (ROWS < 1) {
        printf("Error");
        exit(0);
    }
    for (int i = 0; i < ROWS; i++) {
        matrix->row = NULL;
        matrix->Next = malloc(sizeof(ListSTR));
        matrix = matrix->Next;
    }
    free(matrix);
}
void ReadMatrix(ListSTR* matrix, int ROWS, int COLUMNS, char* filename) {
    FILE* fp = fopen(filename, "r");
    char c;
    int count = 1;
    while (c = getc(fp) != '\n') {}
    while (1) {
        while (1) {
            int isNULL = 0;
            char val[MAX_SIZE_OF_VAL];
            while (isWhitespace(c = getc(fp))) {}
            int i = 0;
            int value;
            int row;
            while (1) {
                if (c == '-' && i == 0) {
                    val[i++] = c; val[i] = 0;
                }
                else if (isNum(c)) {
                    val[i++] = c; val[i] = 0;
                }
                else if (isWhitespace(c)) {
                    if (c == '\n') {
                        printf("Error");
                        exit(1);
                    }
                    value = strtol(val, NULL, 10);
                    break;
                }
                else if (c == 'N') {
                    if (matrix->row != NULL) {
                        printf("Error");
                        exit(1);
                    }
                    isNULL = 1;
                    break;
                }
                else {
                    printf("Error");
                    exit(1);
                }
                c = getc(fp);
            }
            while (isWhitespace(c = getc(fp))) {}
            char rows[MAX_SIZE_OF_MATRIX];
            i = 0;
            while (1) {
                if (isNULL) {
                    if (c == 'U') {
                        for (int i = 0; i < 2; i++) {
                            c = getc(fp);
                            if (c != 'L') {
                                printf("Error");
                                exit(1);
                            }
                        }
                        break;
                    }
                }
                if (isNum(c)) {
                    rows[i++] = c; rows[i] = 0;
                }
                else if (isWhitespace(c)) {
                    row = strtol(rows, NULL, 10);
                    if (row >= ROWS) {
                        printf("Error");
                        exit(1);
                    }
                    break;
                }
                else if (c == EOF) {
                    row = strtol(rows, NULL, 10);
                    if (row >= ROWS) {
                        printf("Error");
                        exit(1);
                    }
                    break;
                }
                else {
                    printf("Error");
                    exit(1);
                }
                c = getc(fp);
            }
            if (!isNULL) {
                Add(&(matrix->row), value, row);
            }
            else {
                break;
            }
            if (c == '\n' || c == EOF) {
                break;
            }
        }
        count++;
        if (count >= ROWS) {
            break;
        }
        matrix = matrix->Next;
    }
    fclose(fp);
}
void Transpose(ListSTR* matrix, ListSTR* result, int ROWS, int COLUMNS) {
    for (int i = 0; i < ROWS; i++) {
        if (matrix->row == NULL) {
            if (i < ROWS) {
                matrix = matrix->Next;
            }
            continue;
        }
        STR* point = matrix->row;
        while (1) {
            AddToIndex(&result, point->Row, point->Val, i);
            if (point->Next != NULL) {
                point = point->Next;
            }
            else {
                break;
            }
        }
        if (i < ROWS) {
            matrix = matrix->Next;
        }
    }
}
int Trans() {
    setlocale(LC_ALL, "Rus");
    int ROWS, COLUMNS;
    char* file = "Text.txt";
    GetRowsAndColums(file, &ROWS, &COLUMNS);
    ListSTR* matrix = malloc(sizeof(ListSTR));
    Initialize(matrix, ROWS);
    ListSTR* result = malloc(sizeof(ListSTR));
    Initialize(result, COLUMNS);
    ReadMatrix(matrix, ROWS, COLUMNS, file);
    printf("Матрица \n");
    printMatrix(matrix, ROWS, COLUMNS);
    Transpose(matrix, result, ROWS, COLUMNS);
    printf("Матрица транспонированная \n");
    printMatrix(result, COLUMNS, ROWS);
    clean(matrix, ROWS); clean(result, COLUMNS);
    return 0;
}

截图有一些错误 截图有一些错误

c
  • 1 1 个回答
  • 24 Views

1 个回答

  • Voted
  1. Best Answer
    Harry
    2023-12-22T01:04:12Z2023-12-22T01:04:12Z
    typedef struct STR {
        int Val;
        int Row;
        struct STR* Next;
    } STR;
    

    注意你错过的事情struct。

    • 1

相关问题

  • free 出于某种原因不会从内存中删除数组

  • 请帮助代码

  • 为什么 masm 对字符串或文本文字太长发誓,为什么在结构中设置 db 或 dw?

  • 如何将数字拆分为位并将其写入 C 中的数组?

  • 如何以给定的角度移动物体?

  • 解决“子集和问题”的时效算法

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5