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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    i = 0; j < 10; i++)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,275
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 03:45 AM
  2. Replies: 1
    Last Post: 10-27-2006, 02: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, 11:05 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. for loop or while loop
    By slamit93 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 05:13 AM

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