简体   繁体   English

在 c 中的结构和双指针处弹出错误

[英]Error pops up at structs and double pointers in c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CHARS 10
char **readText(void) ;
typedef struct text_t
{
    char * * mt;
    int words;
}
Text_t;
int main(void)
{

    int i, words;
    Text_t.mt = readText();
    for (i=0; i<words; i++)
        printf("%s\n", Text_t.mt[i]);
    return 0;
}

char **readText(void)
{
    *Text_t.mt = NULL;
    char *word;
    *words = 0;
    while (scanf("%s", word=malloc(CHARS*sizeof(char))),
            strcmp(word,"END"))
    {
        (*words) ++;
        Text_t.mt = realloc(mytext, (*words)*sizeof(char *));

        Text_t.mt[*words-1] = word;
    }
    free(word);
    return Text_t.mt;
}

The goal of this programm is to take some words as input from the user untill the word "END" is entered.该程序的目标是将一些单词作为用户的输入,直到输入单词“END”。 Then we print the given words with the same order as they were entered.然后我们按照输入的顺序打印给定的单词。 The problem is when I try to run the programm, this error comes up:问题是当我尝试运行该程序时,出现此错误:

main.c|16|error: expected identifier or '(' before '.' token|

You probably mean你可能是说

   Text_t tt;
   tt.mt = NULL;

ie IE

  • create an instance ot the Text_t struct创建 Text_t 结构的实例
  • set its 'mt' pointer to NULL将其“mt”指针设置为 NULL

whether thats the correct thing for your main aim I cant say, but at least it will get you past your current compile error我不能说这对你的主要目标是否正确,但至少它会让你克服当前的编译错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM