C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-18-2009, 10:11 AM   #1
Astrophysics student
 
Ayreon's Avatar
 
Join Date: Mar 2009
Location: Netherlands
Posts: 70
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...
Ayreon is offline   Reply With Quote
Old 03-18-2009, 10:13 AM   #2
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,556
i = 0; j < 10; i++)
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 03-18-2009, 10:13 AM   #3
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 03-18-2009, 10:44 AM   #4
Astrophysics student
 
Ayreon's Avatar
 
Join Date: Mar 2009
Location: Netherlands
Posts: 70
Thanks vart, that was the problem . Needed a fresh pair of eyes apparently.
__________________
Nothing to see here, move along...
Ayreon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
loop the loop - feeling foolish estos C Programming 2 04-07-2007 02:45 AM
A mini-compilier I made stuck in an infinite loop (lots of code) dan06 C++ Programming 1 10-27-2006 01:21 PM
The Bludstayne Open Works License frenchfry164 A Brief History of Cprogramming.com 8 11-26-2003 11:05 AM
fopen(); GanglyLamb C Programming 8 11-03-2002 12:39 PM
for loop or while loop slamit93 C++ Programming 3 05-07-2002 04:13 AM


All times are GMT -6. The time now is 12:04 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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