Re: Problems during file writing or During Type Casting ?
Re: Problems during file writing or During Type Casting ?
- Subject: Re: Problems during file writing or During Type Casting ?
- From: Christian Walther <email@hidden>
- Date: Sat, 20 May 2006 15:02:04 +0200
Tom Wenger wrote:
I need to write the informations inside this NSArray
into another file,for that i gave the following codes But the
result i am
getting in the newly created file is a
blank one.
NSArray *object=[_inspectingGraphicView graphics];
NSString *GetValue=(NSString*)object;
Look up type casting (of pointers) in a C reference. What you're
doing here is just treating the NSArray* as an NSString*, which
doesn't magically convert the object it points to to an NSString.
// get the path for saving the file
const char* thePath;
NSString *currentPath;
NSString *applicationName;
NSString* thePathString = [theSavePanel filename];
thePath = [thePathString cString];
// open a new file
FILE* theFile = fopen(thePath, "w");
if(theFile != NULL)
{
fwrite(GetValue,1,11111,theFile);
}
// close the file
fclose(theFile);
Most likely what you want is something like the following (untested),
FILE* theFile = fopen([[theSavePanel filename]
fileSystemRepresentation], "w");
if (theFile != NULL) {
fputs([[[_inspectingGraphicView graphics] description]
UTF8String], theFile);
fclose(theFile);
}
or, completely cocoaified,
[[[_inspectingGraphicView graphics] description] writeToFile:
[theSavePanel filename] atomically: YES encoding:
NSUTF8StringEncoding error: NULL];
or even (if your NSArray only contains property-list-compatible data)
[[_inspectingGraphicView graphics] writeToFile: [theSavePanel
filename] atomically: YES];
-Christian
_______________________________________________
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