-1

input :
T - test cases
and then next T lines. Each line contains a word(string). I want to take them as an input and store them in a 2D array, like

char string[T][ ];

example input :

3
abcd
bcdb
ddc

I don't want to use cs50's string data type.

1
  • Use vectors in Standard Template Library in C++
    – sinister
    Nov 29, 2014 at 1:30

1 Answer 1

0

You need to determine the maximum length of any string that your program takes as input then to create your array like that

char T[n][max];

where n is the total number of strings and max is the maximum length of a string + 1 for the null character.

1
  • char* T[n] is an array of pointers to chars and can be used to store dynamically sized strings (you'll need to malloc). If you want a dynamic array of dynamically sized strings then you will need to use a method such as linked lists instead of a static array.
    – Nick Young
    Jan 22, 2016 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .