Thread: Newbie question: Kernighan-Ritchie C book- problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    With all due respect to Mitakeet's post (he correctly pointed out your problems), I would add that looking in my copy of K&R2, it seems that your code should look like the following:

    Code:
    #include<stdio.h>
    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("Ta psifia einai");
                    for( i = 0 ; i < 10 ; ++i)
                      printf(" %d",ndigit[i]);
                      printf(", ta leyka diastimata einai %d, kai oi alloi xaraktires %d", nwhite, nother);
                      printf(".Sas eyxaristoume pou mas kalesate.\n");
    
                      }
    edit:: Dave, you type too fast!
    Last edited by kermit; 06-29-2005 at 01:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  2. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 12:27 PM
  3. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  4. Problem with code (newbie question)
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-31-2002, 01:39 AM
  5. newbie with an old book
    By Joseph in forum C Programming
    Replies: 13
    Last Post: 08-28-2001, 05:06 PM