I am trying to compile and run a simple objective c code BUT I am doing it on Windows.I am using the GNU Step and it is extremely hard for me to debug it and understand what is going on runtime.I am a .NET developer and I always use the Debugger in Visual Studio to follow the data flow and stuf but here ...... it is realy annoying.I don't have a Mac Book so I don't have the XCode too.
Can anybody tell me what is the problem in that peace of code?It is quite simple and it would be great if someone who has a Mac could debug it for me and tell me what is wrong.
The idea of the code is that it reads out a text file line by line and then on every 3 lines of code it makes an Object of NSMutableArray and adds it to another NSMutableArray.Here it is:
The read_line function:
int read_line(FILE *in, char *buffer, size_t max)
{
return fgets(buffer, max, in) == buffer;
}
The content of the text file:
Sophie Ellis-Bextor
71222
5.01
Inna Morales
61223
6.00
Kortez Domingues
41231
3.25
The code in the main:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
FILE *in;
if((in = fopen("C:...\\Input.txt", "rt")) != NULL)
{
char line[256];
NSMutableArray* resultArray = [[NSMutableArray alloc] init];
while(read_line(in, line, sizeof line))
{
NSString *currentLine = [[NSString alloc] initWithUTF8String:line];
[resultArray addObject:currentLine];
}
NSMutableArray*resultObjectsArray =[[NSMutableArray alloc] init];
NSMutableArray*tmpArray =[[NSMutableArray alloc] init];
for(int i=0 ; i <[resultArray count];i++)
{
if(i%4 == 3)
{
[resultObjectsArray addObject:tmpArray];
[tmpArray removeAllObjects];
NSLog(@"Here we add a new object");
}
else
{
[tmpArray addObject:[resultArray objectAtIndex:i]];
NSLog(@"%@",[resultArray objectAtIndex:i]);
}
}
fclose(in);
NSLog(@"First object in the result Array: %@",[[resultObjectsArray objectAtIndex:0] objectAtIndex:0]);
}
[pool drain];
All that I can see is that on the
NSLog(@"First object in the result Array: %@",[[resultObjectsArray objectAtIndex:0] objectAtIndex:0]);
line I get the next error: Uncaught Exception NSRangeException, reason:Index 0 is out of range 0 (in 'objectAtIndex:')