There are 3 ways to solve this problem.
1) Become a "fileNameString" static
static char fileNameString[100];
2) The subscriber of the function 'getSegmentFileName' must pass the character buffer 'segmentFileName' to the called subscriber ie
getSegmentFileName(file, lineLength, mid, segmentFileName);
In this case, you need to change the function arguments
char* getSegmentFileName(FILE *file, int lineLength, int lineNumber, char *segmentFileName) { ..... strcpy(segmentFileName, fileNameString);
3) This way you can dynamically allocate memory for the NameString file. Dynamic memory is allocated on the heap, and it will not be lost when the function returns. That way you can safely use it in the indexSearch function.
char* getSegmentFileName(FILE *file, int lineLength, int lineNumber) { char *fileNameString = (char *)malloc(100 * sizeof(char));
In this case, you need to free the memory indicated by fileNameString using free
snibu source share