loop is running twice

This is a discussion on loop is running twice within the C Programming forums, part of the General Programming Boards category; the inner loop in the createGraph() is getting executed twice while reading status for each edge...does anyone know..y is it ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    loop is running twice

    the inner loop in the createGraph() is getting executed twice while reading status for each edge...does anyone know..y is it happenning??...is the code considering "enter" as another input value??
    Attached Files Attached Files

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Post your code here... don't make us chase it.

  3. #3
    Registered User sagar474's Avatar
    Join Date
    Jun 2011
    Location
    Kakinada
    Posts
    56
    Code:
     printf("\nIs there any edge between %d and %d vertices??(y)",i,j);
            scanf("\n%c",&ch);//add  "\n" in scanf ();
    add \n in scan f before %c

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by sagar474 View Post
    Code:
     printf("\nIs there any edge between %d and %d vertices??(y)",i,j);
            scanf("\n%c",&ch);//add  "\n" in scanf ();
    add \n in scan f before %c
    Nope, \n isn't what you want here ... use a space ... scanf(" %c",&ch) ... this tells scanf() to skip over all invisible characters and wait for your entry. (It's documented in most C library help files, look it up.)

  5. #5
    Registered User sagar474's Avatar
    Join Date
    Jun 2011
    Location
    Kakinada
    Posts
    56
    thank you for your information. commonTater .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't get loop to keep running
    By mytrademark in forum C Programming
    Replies: 2
    Last Post: 11-01-2011, 07:08 PM
  2. running through a loop using pointers
    By boy in forum C Programming
    Replies: 43
    Last Post: 08-19-2011, 05:43 PM
  3. For loop not running properly
    By Todd88 in forum C++ Programming
    Replies: 21
    Last Post: 04-04-2008, 06:27 PM
  4. Running a program in a loop
    By Robert_Sitter in forum C# Programming
    Replies: 7
    Last Post: 01-27-2006, 10:09 AM
  5. Running triangles through loop
    By shanedudddy2 in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2003, 12:59 AM

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