Could the data member being poorly allocated or buffer overflow cause this to get caught in an infinite loop? Here's the declaration and the allocation:
Code:
struct listNode { /* self-referential structure */
char data[30];
int length;/*Length of the word, will actually be low by one*/
struct listNode *nextPtr;
};
typedef struct listNode LISTNODE;
typedef LISTNODE *LISTNODEPTR;
struct paragraph { /* The starting nodes of each paragraph, as well as links to the next paragraph*/
LISTNODEPTR start;
struct paragraph *nextParagraph;
};
typedef struct paragraph *PARAGRAPHPTR;
void insert(LISTNODEPTR *);
void pop(LISTNODEPTR *, char[]);
int isEmpty(LISTNODEPTR);
main()
{
/* Declarations */
char currentLine[125];
char tempWord[30];
int wordsInLine, extraSpaces;
int linePos, lineSize, wordSize=0;
int i, j;
char filename[20];
FILE *fptr;
int testChar = '0';
int newParagraph = FALSE;
int newWord = FALSE;
LISTNODEPTR endOfLine;
LISTNODEPTR startOfFile;
endOfLine = malloc(sizeof(LISTNODEPTR));
startOfFile = malloc(sizeof(LISTNODEPTR));
startOfFile->nextPtr = NULL;
startOfFile->length = 0;
PARAGRAPHPTR firstPara;
firstPara = malloc(sizeof(PARAGRAPHPTR));
firstPara->start = startOfFile;
firstPara->nextParagraph = NULL;
PARAGRAPHPTR currentPara = firstPara;
LISTNODEPTR currentWord = startOfFile;
currentWord->length = 0;
printf("%d ", currentWord->length);
/* Get the file and user input*/
printf("Please input the file that you would like to get text from\n");
scanf("%s", filename);
fptr = fopen(filename, "r");
printf("Please input the number of characters per line for the text\n");
scanf("%d", &lineSize);
currentWord->length = 0;
/*Put the file into paragraphs*/
and then the above code is used. I know that it's an infinite loop, it's not exiting early or anything. Thanks for your help.