Thread: Problem with limiting inputs of char functions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by hobolux View Post
    I want him to enter
    "text\n"
    "text\n"
    "text\n"
    "\n" // type this to exit
    3 // output if all 3 sentences are palindromes
    I see, the behavior would be the same, with the last two characters, both '\n', being located at i-2 and i-1, you are checking i-1 ('\n') and i (garbage), that is why the loop isn't stopping


    edit: actually, the problem looks worse than that,
    Code:
     do
            {
                scanf("%c", &words[i]);
                
                i++;
            } while(words[i] != '\n');
    always checks garbage (the data is entered in words[0] and you check to see if words[1] contains '\n')
    Last edited by ಠ_ಠ; 10-01-2010 at 01:17 PM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. problem with reading and writing
    By yahn in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2006, 04:38 PM
  5. problem printf after inserting single list from file
    By jetfreggel in forum C Programming
    Replies: 3
    Last Post: 04-15-2003, 02:30 PM