I'm working on a project right now that involves linked lists. I've got part of it done, and it complies without any errors currently. However, when I execute it, nothing happens. It apparently doesn't even start int main.
Here's the program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct listNode
{
char fname[40];
char lname[40];
char address[100];
char pcode[6];
char phone[10];
struct listNode *nextPtr;
};
typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;
void insert (ListNodePtr *sPtr);
void printList (ListNodePtr currentPtr);
int main ()
{
ListNodePtr startPtr = NULL;
insert(&startPtr);
printList(startPtr);
}
void insert (ListNodePtr *sPtr)
{
ListNodePtr newPtr;
ListNodePtr previousPtr;
ListNodePtr currentPtr;
newPtr = malloc(sizeof(ListNode));
char fname[40];
char lname[40];
char address[100];
char pcode[6];
char phone[10];
char c;
int cnt = 0;
printf("First Name: ");
while (c != '\n');
{
scanf("%c", &fname[cnt]);
cnt++;
}
cnt = 0;
printf("Last Name: ");
while (c != '\n');
{
scanf("%c", &lname[cnt]);
cnt++;
}
printf("Address: ");
while (c != '\n');
{
scanf("%c", &address[cnt]);
cnt++;
}
cnt = 0;
printf("Postal Code: ");
while (c != '\n');
{
scanf("%c", &pcode[cnt]);
cnt++;
}
printf("Phone Number: ");
while (c != '\n');
{
scanf("%c", &phone[cnt]);
cnt++;
}
cnt = 0;
strcpy(fname, newPtr -> fname);
strcpy(lname, newPtr -> lname);
strcpy(address, newPtr -> address);
strcpy(pcode, newPtr -> pcode);
strcpy(phone, newPtr -> phone);
newPtr -> nextPtr = NULL;
previousPtr = NULL;
currentPtr = *sPtr;
previousPtr -> nextPtr = newPtr;
newPtr -> nextPtr = currentPtr;
}
void printList (ListNodePtr currentPtr)
{
if (currentPtr == NULL)
{
printf("List is empty.\n\n");
}
else
{
printf("The list is:\n");
while (currentPtr != NULL)
{
printf("%s\n", currentPtr -> fname);
printf("%s\n", currentPtr -> lname);
printf("%s\n", currentPtr -> address);
printf("%s\n", currentPtr -> pcode);
printf("%s\n", currentPtr -> phone);
currentPtr = currentPtr -> nextPtr;
}
printf("NULL\n\n");
}
}
However, when I execute it, nothing happens. I've put random printf statements in to see where it stops, and even ones I put at the beginning of main didn't execute. What am I missing here?