How to create an array of fixed-length strings in C?

I am trying to create an array of fixed-length strings in C, but you had minor problems. The problem I am facing is that I get a segmentation error.

Here is the goal of my program: I would like to set the array strings by index using data read from a text file. Here is the gist of my current code (I apologize that I could not add all my code, but it is quite long and most likely will just cause confusion):

//"n" is set at run time, and 256 is the length I would like the individual strings to be
char (*stringArray[n])[256];
char currentString[256];

//"inputFile" is a pointer to a FILE object (a .txt file)
fread(&currentString, 256, 1, inputFile);
//I would like to set the string at index 0 to the data that was just read in from the inputFile
strcpy(stringArray[i], &currentString);
+4
source share
1 answer

, 256 , , 257 , \0 null.

typedef char FixedLengthString[257];
FixedLengthString stringArray[N];
FixedLengthString currentString;

, char* const char* FixedLengthString ( ).

+4

Source: https://habr.com/ru/post/1614890/


All Articles