Thread: Program executes, but doesn't start

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    1

    Program executes, but doesn't start

    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?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
            while (c != '\n');
            {
                    scanf("&#37;c", &fname[cnt]);
                    cnt++;
            }
    Drop those semicolons.

    Also see this FAQ: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make my program run on windows start up
    By kantze in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 03-24-2007, 11:14 AM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. How to start program from subfolder
    By trancedeejay in forum C Programming
    Replies: 2
    Last Post: 04-01-2006, 03:39 PM
  4. Start up program
    By Breetai in forum Windows Programming
    Replies: 2
    Last Post: 01-11-2003, 01:12 PM
  5. Start a program
    By FunkeeMunkee in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 07:18 PM