Thread: Need help with looping for reading external files!

  1. #16
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Code:
    0==x;                                            //Sets X=0 meaning the program can continue
    I think you still haven't understood that there is a *difference* between assignment and comparison!!
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  2. #17
    Registered User
    Join Date
    Jan 2012
    Posts
    27
    Quote Originally Posted by QuantumPete View Post
    Code:
    0==x;                                            //Sets X=0 meaning the program can continue
    I think you still haven't understood that there is a *difference* between assignment and comparison!!
    Why am I wrong here?.

    EDIT:
    Or do you mean it's right to use == when using for example:
    Code:
    if(1==x)
    and
    Code:
    while(0==y)
    But isn't right to say

    Code:
    if(1==x)
    {
    0==y}
    and should instead put
    0=y ?
    Last edited by MstrKurt; 03-28-2012 at 05:08 PM.

  3. #18
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Two equals signs, ==, compares two things. All you do with that statement is compare 0 to x, but you don't do anything special depending on whether or not x is zero. That is, you don't make any decisions based on that fact, no if/else, no loops, nothing. That statement by itself does nothing useful, the results of the comparison are immediately discarded*.

    One equal sign, =, is used to assign things. If you mean to assign the value 0 to x, you must put x = 0;. The variable you are assigning to goes on the left. What you want to assign to it goes on the right. That can be a number, like 0, and expression like 3 * y + 42, or the result of a function call, among other things.

    I think it's time for you to go back and re-read the first few chapters of your C textbook to iron out some of these basics.

    * A good compiler will warn you of this. Perhaps you need to turn up the warnings on your compiler, so you will get a warning message like "statement has no effect".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading from file. problem with looping
    By dmnd in forum C Programming
    Replies: 2
    Last Post: 03-11-2011, 02:15 AM
  2. looping through all files in a directory
    By caggles in forum C Programming
    Replies: 2
    Last Post: 05-25-2009, 04:35 PM
  3. using external files
    By gillypie in forum C++ Programming
    Replies: 1
    Last Post: 01-04-2008, 04:44 PM
  4. Reading external files, (not!!)
    By MichaelStanley in forum C++ Programming
    Replies: 15
    Last Post: 05-25-2003, 03:23 PM
  5. external files
    By DoItAllMom115 in forum C++ Programming
    Replies: 1
    Last Post: 04-13-2003, 04:04 PM