Code:
#include <stdio.h>
#include <stdlib.h>
#include <crtdbg.h>
#include <string.h>
#define MEM_ERROR printf("Error, could not access file!\n")
#define MAX_SIZE 1000
#define FLUSH while(getchar() != '\n')
int getSize (void);
char** buildList (int);
FILE* fp1;
int main (void)
{
int size;
char** list;
size = getSize();
printf("%d is the size\n", size);
list = buildList(size);
free(list);
printf( _CrtDumpMemoryLeaks() ? "\nMemory Leak\n" : "\nCongratulatons! No Memory Leak\n");
system("pause");
return 0;
}
int getSize (void)
{
int size;
if(!(fp1 = fopen("gpa.txt", "r")))
MEM_ERROR;
fscanf(fp1, "%d", &size);
return size;
}
char** buildList (int size)
{
char** list;
char temp[MAX_SIZE];
char* pFirst;
char* pLast;
int i;
if(!(list = (char**)calloc (size + 1, sizeof(char*))))
MEM_ERROR;
/*
while(!feof(fp1))
{
(fgets(temp, MAX_SIZE, fp1));
fputs(temp, stdout);
}
*/
i = 0;
while((fgets(&temp[i], sizeof(temp[i]), fp1)) != NULL)
{
fputs(&temp[i++], stdout);
getchar();
}
fclose(fp1);
return list;
}