Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

multinode

macrumors regular
Original poster
Feb 4, 2011
150
0
I have the following code:
Code:
int main(int argc, char *argv[]) {
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        FILE *ftest;
	int size, i;
	char *string;
	NSString *myNSString = [NSString alloc];
	
	ftest = fopen("/form.txt", "r");
	stat(name, &stbuf);
	myBuffer = calloc(1, size = stbuf.st_size);
	
	string = myBuffer;
	fread(myBuffer, 1, size, ftest);
	for(i=0; i<size; i++){
		if(myBuffer[i]==0x09) {
			myBuffer[i]=0;			
 --->>		        myNSString = [myNSString initWithCString:string encoding:1];
			string = &myBuffer[i+1];
			}
                }
        }

The problem I have is that reinitializing myNSString (at the line with --->>) throws an exception "selector not recognized" at the NSObject level. Is this a problem with myNSString being auto released? Or what else is my problem please?
 
Last edited:
Objective-c beginner tutorial

Why do u right in C and not Objective-c?

why r u writing code in the main function?
no code should be written there except for the existing code in the beginning.

why r u allocing an object without initializing it?
NSString *myNSString = [NSString alloc];

i think u should read a beginner tutorial on objective-c.
 
Why do u right in C and not Objective-c?

why r u writing code in the main function?
no code should be written there except for the existing code in the beginning.

why r u allocing an object without initializing it?
NSString *myNSString = [NSString alloc];

i think u should read a beginner tutorial on objective-c.

I wrote code in main() to test out some concepts first ... this is just temporary code.

I don't initialize immediately because I initialize later in the code.

The C code is because I need to prepare the data that comes in from the fread() before I do the Obj C operations ... that's more easily done in C. What's shown here is just a snippet of my app.
 
The problem I have is that reinitializing myNSString (at the line with --->>) throws an exception "selector not recognized" at the NSObject level. Is this a problem with myNSString being auto released? Or what else is my problem please?

Don't do that.

First, most objects can't be reinitialized. init methods are almost never designed to accomodate that.

Second, NSString is immutable. It's objects are not designed to be mutated after init.

http://developer.apple.com/library/...nceptual/ObjectiveC/Chapters/ocAllocInit.html
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.