#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//the int values
int values[5] = {
5,
4,
3,
2,
1
};
int i;
NSError *error;
//store them into a file
NSMutableString *mutstr = [[NSMutableString alloc] init];
for(i = 0; i < 5; i++)
[mutstr appendFormat:@"%i ", values[i]];
//write to file
[mutstr writeToFile:@"Data.txt" atomically:YES encoding:NSUnicodeStringEncoding error:&error];
//read from the file
NSString *string = [[NSString alloc] initWithContentsOfFile:@"Data.txt"];
if(string == nil)
{
NSLog(@"Error reading file");
return 1;
}
//scan the integers from the file
NSScanner *scanner = [[NSScanner alloc] initWithString:string];
while([scanner isAtEnd] == NO)
{
NSInteger integer;
[scanner scanInt:&integer];
NSLog(@"Value : %d", integer);
}
[pool drain];
return 0;
}