Welcome to the iMore Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 3 of 3
  1. Thread AuthorThread Author   #1  
    Moriquendi's Avatar
    iPhone Nanite

    1 Posts

    Default Reading binary file into array


    I want to read binary file on my iPhone.
    I have .txt file witch store information about array: int[6000][9]
    How can I put this data into array in my code?

    I tried this:
    	int mapa1[6000][9];
    	NSFileHandle* file = [NSFileHandle fileHAndleForReadingAtPAth: @"level1.txt"];
    	[[file readDataOfLength:4] getBytes:mapa1];
    	mapa1 = NSSwapLittleIntToHost(mapa1);
    But on the last line I receive error: "Incompatible types in assigment"
    So I don't know how to copy this binary file into the array...

    Can someone help me?
  2. #2  
    mobilebreak's Avatar
    iPhone Beginner

    98 Posts
    Global Posts
    99 Global Posts


    I'm not familiar with this specific code but i do notice a coupe of possibilities:

    usually in objective C file names are referenced by name and then type, not with dot notation


    NSFileHandle* file = [NSFileHandle fileHandleForReadingAtPath: @"level1" ofType: @"txt"];

    also, watch your capitals HAndle instead of Handle.
  3. #3  
    msteven's Avatar
    iPhone Nanite

    4 Posts


    You might try looking at NSData initWithContentsOfFile and the bytes property.
    You could also parse the file and populate the array manually.

Posting Permissions