• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trouble reading a binary file.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble reading a binary file.


  • Subject: Re: Trouble reading a binary file.
  • From: Henry McGilton <email@hidden>
  • Date: Mon, 13 Dec 2004 09:14:11 -0800


On Dec 13, 2004, at 7:51 AM, April Gendill wrote:

Below is the code I'm trying to use to read a binary file. I'm getting an empty string though.. Can any one shed some light on this?



FILE * fptr;
		fptr = fopen([[panel filename]cString],"rb");
		char chr;
		NSMutableString * fd =[[NSMutableString alloc]init];

		while(chr =getc(fptr) != EOF){
			[fd appendString:[NSString stringWithFormat:@"%c",chr]];
			}

In addition to the suggestions made by Glenn Andreas and Marcel Weiher, the code snippet:

    while(chr = getc(fptr) != EOF) {
         . . .
    }

is incorrect, as the  !=  operator binds tighter than the
= (assignment) operator.  If you use this idiom in future
codes, you need to write it thus:

    while((chr = getc(fptr)) != EOF) {
         . . .
    }

so that the result of the assignment is then compared to
EOF.

    Cheers,
		........  Henry

===============================+============================
  Henry McGilton, Boulevardier |    Trilithon Software
   Objective-C/Java Composer   |     Seroia Research
-------------------------------+----------------------------
  mailto:email@hidden   |   http://www.trilithon.com
                               |
===============================+============================

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Trouble reading a binary file. (From: April Gendill <email@hidden>)

  • Prev by Date: Re: waiting on a thread
  • Next by Date: Re: How can I implement labels without the overhead of an NSTextField?
  • Previous by thread: Re: Trouble reading a binary file.
  • Next by thread: Re: Trouble reading a binary file.
  • Index(es):
    • Date
    • Thread