Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
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




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>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.