小编Xer*_*nos的帖子

如何将typedef结构传递给函数?

目前我正在努力

void avg(everything)
Run Code Online (Sandbox Code Playgroud)

但这给了我错误:

error: subscripted value is neither array nor pointer
Run Code Online (Sandbox Code Playgroud)

当我今天早些时候遇到这个错误时,那是因为我没有正确地将2D数组传递给函数.所以我认为这是相同的但我找不到正确的格式来传递它.

这是我的typedef:

typedef struct structure
{
char names[13][9];
int scores[13][4];
float average[13];
char letter[13];
} stuff;
Run Code Online (Sandbox Code Playgroud)

这是我的typedef数组:

stuff everything[13];
Run Code Online (Sandbox Code Playgroud)

c arrays struct function

3
推荐指数
1
解决办法
2万
查看次数

从不兼容的指针类型传递'y'的参数x

这是一个程序,主要是为了让我在尝试在更大的程序中使用它之前获得fopen和类似语法的悬念.因此,程序试图完成的唯一事情是打开文件(scores.dat),读取该文件中的数据,将其分配给数组,然后打印数组.

这是我有错误的代码段:

int scores[13][4];

FILE *score; 
score = fopen("scores.dat", "r");

fscanf("%d %d %d %d", &scores[0][0], &scores[0][1], &scores[0][2], &scores[0][3]);

printf("%d &d %d %d", scores[0][0], scores[0][1], scores[0][2], scores[0][3]);

fclose(score);
Run Code Online (Sandbox Code Playgroud)

编译时,我收到错误:

text.c: In function 'main':
text.c:15: warning: passing argument 1 of 'fscanf' from incompatible pointer type
text.c:15: warning: passing argument 2 of 'fscanf' from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

如果它很重要,scores.dat看起来像这样:

88 77 85 91 65 72 84 96 50 76 67 89 70 80 90 99 42 65 66 72 80 82 85 83 …
Run Code Online (Sandbox Code Playgroud)

c arrays file

0
推荐指数
1
解决办法
1646
查看次数

标签 统计

arrays ×2

c ×2

file ×1

function ×1

struct ×1