Can't get out of function

This is a discussion on Can't get out of function within the C Programming forums, part of the General Programming Boards category; Code: case 'H': hire(&infile, lineOfText, &firstEmployee); printList(firstEmployee); printf("hello"); break; Code: void printList(struct employee *currentEmployee) { int num=ONEI; if (currentEmployee == ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    37

    Can't get out of function

    Code:
    case 'H':
    	    hire(&infile, lineOfText, &firstEmployee);
    	    printList(firstEmployee);
                printf("hello");
                break;
    Code:
    void printList(struct employee *currentEmployee)
    {
    	int num=ONEI;
    	if (currentEmployee == NULL)
    	{
    		printf("No employees have been hired yet\n");
    	}
    	else
    	{
    		printf("The Employees Are\n\n");
    		
    		do{
    			printf("%d %X  %s %s %d %s $%lf $%lf %X\n", num,
    											         currentEmployee,
    										        currentEmployee->firstName,
    											currentEmployee->lastName,
    									                currentEmployee->id,
    											currentEmployee->class,
    										currentEmployee->salary[ZEROI],
    										currentEmployee->salary[ONEI],
    										currentEmployee->nextEmployee);
    			 currentEmployee = currentEmployee->nextEmployee;
    			num += ONEI;
    		}while (currentEmployee->nextEmployee != NULL);
    	    printf("%d %X  %s %s %d %s $%lf $%lf NULL\n", num,
    													 currentEmployee,
    											currentEmployee->firstName,
    											currentEmployee->lastName,
    										        currentEmployee->id,
    										        currentEmployee->class,
    										  currentEmployee->salary[ZEROI],
    										currentEmployee->salary[ONEI]);
    	}
    	printf("test\n");
    }
    In the switch statement my hire functions runs and hires the employees fine, the program then goes into the printList function and prints everyone like it should, it will get to the printf("test\n"); and print out "test". However after this I just get a blank line and it does not hit the printf("hello"); in the switch statement outside of the printList function. Why is it not leaving the printList function?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Note that printf() statements that do not end in newlines do not always appear instantly. If you want to make sure that the output buffer is flushed, either print a newline or call fflush(stdout). I'm not sure if this is your problem, but it might be.

    In addition, printf() does not work with %lf. scanf() uses %f for floats and %lf for doubles, but printf() uses %f for both floats and doubles.
    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.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    not also that the proper way to print a pointer if
    Code:
    printf("%p", (void*)ptr);
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    37
    That fixed it, thank you sir.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21