LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-08-2004, 09:53 PM   #1
Magus_Rune
LQ Newbie
 
Registered: Jul 2004
Distribution: RedHat (Shrike)
Posts: 8

Rep: Reputation: 0
Question Event Controlled Looping in C++


Hi!
For an assignment I'm trying to read a set of integers from a file and store them in an array. Instead of reading ALL of them, we are suppose the loop is suppose to stop when we reach a -1. I'm attemping to do it with this:
(ps sin is the name of my file variable)
while (1)
{
sin >> x[a];
if (x[a] = -1)
break;
a++;
}


With no luck.

Is there a better way I can create an event controlled loop where my function will stop reading from the file when it reads a -1 as the integer?


Thanks!
 
Old 12-09-2004, 03:55 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Re: Event Controlled Looping in C++

Quote:
Originally posted by Magus_Rune
if (x[a] = -1)
[/B]
Yes there is (try/throw/catch) but it's overkill here. You have an obvious problem with this loop that will cause it to break early. I'd tell you what that is but that would be against the rules (http://www.linuxquestions.org/rules.php; fifth from the bottom).
 
Old 12-09-2004, 04:58 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Please post the declarations of sin, a, and x.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vmalloc area: what exactly is it, and how is it controlled? Elric of Grans Linux - General 2 09-07-2005 11:28 PM
sftp controlled access mb_chris Linux - Security 5 08-25-2005 05:11 PM
Help:xinetd controlled service? sti2envy Linux - Networking 1 10-19-2004 09:16 AM
my redhat9 pc controlled by other PC chris68 Linux - Security 1 10-16-2004 08:45 PM
can user bandwidth be controlled through router? lucastic Linux - Networking 3 09-12-2003 02:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration