Hi,
I'm having problems passing a string array, modifying it, and getting it back into main. Here are the sections of code that I think are relavent:
Function Prototype:
int fillArray(char *[], int);
Array declaration:
char *zipFileNames[ARRAYSIZELIMIT];
Function call:
numberOfFiles = fillArray(zipFileNames, ARRAYSIZELIMIT);
Array processing in function:
fileNameArray[fileNumber] = fileName;
printf("FileNumber %d is filename: %s\n", fileNumber, fileNameArray[fileNumber]);
fileNumber = fileNumber + 1;
Please note that the printf statement is there as a debugging tool, and that it shows that the array is filling properly.
main() statements following function call:
printf("Provide the array index (0 - %d):\n", (numberOfFiles - 1));
scanf("%d", &userPrintAnswer);
if (userPrintAnswer >= 0 && userPrintAnswer < numberOfFiles)
printf("The filename is: %s\n", *zipFileNames[userPrintAnswer]);
Unfortunately, the last line produces:
The filename is: (null)
Any help will be appreciated!
David
I'm having problems passing a string array, modifying it, and getting it back into main. Here are the sections of code that I think are relavent:
Function Prototype:
int fillArray(char *[], int);
Array declaration:
char *zipFileNames[ARRAYSIZELIMIT];
Function call:
numberOfFiles = fillArray(zipFileNames, ARRAYSIZELIMIT);
Array processing in function:
fileNameArray[fileNumber] = fileName;
printf("FileNumber %d is filename: %s\n", fileNumber, fileNameArray[fileNumber]);
fileNumber = fileNumber + 1;
Please note that the printf statement is there as a debugging tool, and that it shows that the array is filling properly.
main() statements following function call:
printf("Provide the array index (0 - %d):\n", (numberOfFiles - 1));
scanf("%d", &userPrintAnswer);
if (userPrintAnswer >= 0 && userPrintAnswer < numberOfFiles)
printf("The filename is: %s\n", *zipFileNames[userPrintAnswer]);
Unfortunately, the last line produces:
The filename is: (null)
Any help will be appreciated!
David