SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)

    C printf statments not executing after reading in input

    Not particularly a .net question but c, not exactly sure where is should go. Anyway, I am following some lessons in a book and I can not seem to get the statements following the while loop to execute. It seems like once I hit enter the program runs the while loop and ignores everything below it. Maybe this is a system issue? I'm on mac os x 10.5 leopard with the dev tools from apple.

    thanks

    Code C:
    #include <stdio.h>
     
    #define IN 1
    #define OUT 0
     
    /* count digits, white space and others */
    main()
    {
     
    	int c, i, nwhite, nother;
    	int ndigit[10];
     
    	nwhite = nother = 0;
     
    	for(i = 0;i < 10; ++i) {
    		ndigit[i] = 0;
    	}
     
    	while( (c = getchar()) != EOF ) {
     
    		if(c >= '0' && c <= '9') {
    			++ndigit[c - '0'];
    		} else if(c == ' ' || c == '\n' || c == '\t') {
    			++nwhite;
    		} else {
    			++nother;
    		}
     
    	}
     
    	printf("digits =");
     
    	for(i = 0;i < 10; ++i) {
    		printf(" %d",ndigit[i]);
    	}
     
    	printf(", white space = %d, other = %d\n", nwhite, nother);
     
    	return 0;
     
    }
    The only code I hate more than my own is everyone else's.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    Finally was able to least isolate this issue. Seems like it is a bug in Eclipse, which I am using to run the program. Now just to figure out how to get around it.

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=159803
    The only code I hate more than my own is everyone else's.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    If anyone knows how to signal the end of a file in the eclipse environment it would be helpful. Looks like for now I will be using the terminal.
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •