There is a txt file with words in three columns (columns are separated by tabs) and varying number of lines. There is a fopen stream, let's call it f . Counting the number of lines in the counter variable has already been written, and now we need an array of strings. It seems that it should be written as char dict[counter][3][lenght] , but: 1. Is the array above a label with rows and i columns containing words of length length ? 2. How to correctly declare this array, if the memory for it should be allocated a function new ? 3. Ideally, a word is a sequence of letters, punctuation and spaces, borders - the beginning / end of a line and tabs. How can I make the word length read into the variable length , and the word itself into the cell of the array? 4. When I address a word, the call goes to dict[i][j] , i from 0 to counter , j from 0 to 3, right? Well, for example, the word in the fifth line in the second column has the address dict[5][2] ?

Thanks for attention.

    1 answer 1

    char dict[counter][3][lenght] is an array of counter arrays, where each array is 3 arrays, each of which is of length length .

    If you get confused in long types - use typedef , don't be shy. for example

     typedef char word[length]; // word - слово, length символов typedef word line[3]; // line - строка из трех слов typedef line text[counter]; // text - counter строк... 

    On the second question, what is the function new in C? Do you mean malloc ? And if you have C ++ and new , then it is better to use vector . And malloc - just call malloc(sizeod(dict)) . But you should know for sure that no word will be longer than length-1 characters, for example. Otherwise, it is better to take an array char* dict[counter][3] - and allocate memory for each line.

    When I refer to a word, the call goes to dict [i] [j], i from 0 to counter, j from 0 to 3, right? Well, for example, the word in the fifth line in the second column has the address dict [5] [2]?

    No, in C, the entire numbering from 0 is yes, but you have a counter in total, which means i has values ​​from 0 to counter-1 . And, accordingly, the word in the fifth line, the second column - dict[4][1] .

    As for how to read lines ... There are different options. Personally, I would read the entire line, and then divide by the tab characters, get the length using strlen .