My loop within loop won't work

This is a discussion on My loop within loop won't work within the C Programming forums, part of the General Programming Boards category; I made a loop which reads from some lines a file. It works fine but now I want the loop ...

  1. #1
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79

    My loop within loop won't work

    I made a loop which reads from some lines a file.
    It works fine but now I want the loop within another loop.

    Once I remove the now commented loop in this code, it doen't show the printf anymore:

    Code:
        //for(i = 0; j < 10; i++) 
           //{   
           for (j = 0; j < N_points - 2 ; j++)
               {
               fgets(string, 512, input);
               sscanf(string, "%lf %lf", &spectrum[i].wavelength[j], &spectrum[i].intensity[j]);
               
               
               printf ("\n %d\t%g    \t%g", j, spectrum[i].wavelength[j], spectrum[i].intensity[j]);
               }
           //}
    Anyone know why?
    Nothing to see here, move along...

  2. #2
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,754
    i = 0; j < 10; i++)
    To be or not to be == true

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,803
    Use a debugger. Maybe N_points <= 2, so the loop never runs at all.

    EDIT:
    Oh wait, once you remove the comments it does not work... haha, ok, vart is probably on the right track here.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    Thanks vart, that was the problem . Needed a fresh pair of eyes apparently.
    Nothing to see here, move along...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loop the loop - feeling foolish
    By estos in forum C Programming
    Replies: 2
    Last Post: 04-07-2007, 02:45 AM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 10:05 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. for loop or while loop
    By slamit93 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 04:13 AM

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