简体   繁体   中英

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. 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

  • create an instance ot the Text_t struct
  • set its 'mt' pointer to 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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