Hi guys this is my first post here,
I am trying to make a c program that reads a text file that is formatted like this
0 human
1 cat
2 dog
3 rat
ect….
So what I am trying to do is put them into an array using the number as the array index and the string as the value.
I will give include the parts that I think would be necessary in solving this problem.
char* memoryBuffer[maxPageNumber - 1];
initBufferFile = fopen("init_buffer_pages.dat", "rt");
//I have used fgets to read each line from a file
fgets(fileInputBuffer, 4100, initBufferFile) == NULL)
//Then used sscanf to separate the number and the string from each line
(sscanf( fileInputBuffer, "%s %s", ¤tNumber, ¤tContents) == 2 )
//if I print the current Number and current contents like this it works fine.
printf("[%d](%s)\n", currentNumber, ¤tContents);
but when I put the contents in the page array like this
memoryBuffer[currentNumber] = currentContents;
and try to print the array item like
printf(memoryBuffer[0]);
or
printf(&memoryBuffer[0]);
it gives a segmentation fault when it runs.
Im guessing its got something to do with the char*[] or the printf’s but im not sure.
If anyone could give me any help It would be greatly appreated.
Cheers



1Likes
LinkBack URL
About LinkBacks


