• 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: read data from an .txt file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read data from an .txt file


  • Subject: Re: read data from an .txt file
  • From: Laurence Harris <email@hidden>
  • Date: Mon, 27 Nov 2006 13:42:27 -0500


On Nov 27, 2006, at 9:52 AM, Jürgen Keser wrote:

Hi,

I create an .txt file that contains some data. Now I want to store all the data
from the .txt file in an char or an Str255.

Which is it? Your code only reads one byte. Why are you creating a text file to store one byte? If the file isn't intended for the user to read, why use a text file?


Here is a snippet of the code I use.
Is this the right way to get the data of the .txt file? How must I go on?


Or is it better to do that with fopen/fread...

FWIW, both Pascal strings (Str255) and FSSpecs are considered legacy data types that should be avoided as much as possible. What you have should work (with the exception of one issue I mention below), but I'm curious as to what kind of data your storing in this file, as there may be a better mechanism for managing this information.


FSSpec spec;
SInt8 tt = true;
short fileRefNum;

err = FSMakeFSSpec(spec.vRefNum,spec.parID,spec.name,&spec);

This doesn't make sense. You haven't initialized any of the fields of spec before using them with FSMakeFSSpec. What exactly do you expect from using random values to create an FSSpec?


err = FSpOpenDF(&spec,tt,&fileRefNum);
long count = 1;
char ch[255];
if(!err){
	err = FSRead(fileRefNum, &count, &ch);

Since ch is an array I believe this should be:

	err = FSRead(fileRefNum, &count, ch);

	if(!err){
		FSClose(fileRefNum);
      }
}

Thanks for any help.

Larry

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


References: 
 >read data from an .txt file (From: Jürgen Keser <email@hidden>)

  • Prev by Date: Re: Optimization questions
  • Next by Date: Re: Debug view: Can't get a variable into the variable view
  • Previous by thread: Re: read data from an .txt file
  • Next by thread: Broken pipe error in Xcode2.4.1
  • Index(es):
    • Date
    • Thread