Thread: a question about a loop

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    72

    a question about a loop

    how can to this loop to take one character at a time ?
    thanks for your answer in advance

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    That's so vague. It's like asking about putting fluid in a car.

    What fluid? Where are you trying to put it? What are you trying to accomplish?

    For your particular question, this is a guess: if you're trying to read a char from a file, char per char, you can use fgetc() in a loop.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Code:
    int c;
    while((c = fgetc(stdin)) != EOF)
    {
        // c has the char... do what you want with it
    }

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    sorry i didn't post the loop
    for(ch=getc(inp); ch!=EOF; ch=getc(inp))

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Why not condense it?

    Code:
    while((ch = getc(inp)) != EOF)
    {
    	/* Code here */
    }

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Naturally 'ch' needs to be an integer if you're testing against EOF.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For loop question
    By JuzMe in forum C++ Programming
    Replies: 11
    Last Post: 04-20-2009, 08:39 AM
  2. Loop question
    By kwood965 in forum C Programming
    Replies: 6
    Last Post: 10-29-2008, 11:12 PM
  3. simple for loop function question
    By felicityxiv in forum C Programming
    Replies: 7
    Last Post: 05-06-2006, 11:43 PM
  4. Please don't laugh...SIMPLE loop question!
    By the_lumin8or in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2006, 01:08 PM
  5. while loop question
    By rayrayj52 in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2004, 05:13 PM