char [n] [100]是什么意思?

时间:2019-03-01 07:53:28

标签: c

我的教授给了我一个C文件,我真的不太了解它。 这是一个从文本文件读取的程序。

#include <stdio.h>
main(){
    int n,m;
    char start[30],end[30];
    FILE *a;
    a=fopen("test.txt","r");
    fscanf(a,"%s",&start);
    fscanf(a,"%s",&end);
    fscanf(a,"%d",&m);
    fscanf(a,"%d",&n);
    printf("\n%s\n%s\n%d\n%d",start,end,m,n);
    char word[n][30];
    int i=0;
    while(!feof(a)){
        fscanf(a,"%s",&word[i]);
        i++;

    }

    for(i=0;i<n;i++)
        printf("\n%s",word[i]);
    fclose (a);

}

这是文本文件:

blah alooa
7 4
hey
boom
stackoverflow
testing

所以,我想知道char word[n][30]是什么意思?为什么它有[n]

2 个答案:

答案 0 :(得分:2)

  

所以,我想知道这个字符[n] [30]是什么意思?

从技术上讲,它是字符的二维VLA。此程序中使用它来存储“ n”个单词,每个单词的最大长度为30个字符。

  

为什么有[n]?

这是一个变量,用于存储文件中的单词数。

在看程序时,可能必须输入8作为https: - {key: 'https', value: ['tcp/443']} - {key: 'app_svc', value: ['tcp/5543', 'udp/5543', 'tcp/3100']} 的值。

答案 1 :(得分:-1)

n是您有单词的数字,并且从文件中读取。 就像您在文件的第一行中存储了一些参数一样