Thread: File to Matrix problem

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    6

    File to Matrix problem

    I am trying to take the data in a file that looks like this (this is the accual data and dataformat.

    Code:
    11111111111
    11111111111
    11111111111
    10000001111
    10101101111
    00101101111
    11101101100
    11111101101
    11111100001
    11111111111
    11111111111
    Now I have tried it a few ways but all end in a segmentation fault. I have tried using fgetc along with atoi, I have tried fgets and using atoi on each index (treating the resulting string as an array) but I am at my whits end. Any help would apprecated.

    I have my matrix define at maze[11][11] and I am using nested for loops and i can loop through and fill with default data like all 0's or 1's, but not with data from the file (and I am checking to make sure the file opens)

    thanks,

    Branden

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Post some of your code...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    6

    The code for my insertion Function

    Sorry frustration is getting to me

    Code:
    void fillmaze(int maze[11][11], FILE *fileptr)
    {
       int row;
       int col;
       char *dump;
    
       for(row=0;row<11;row++){
          printf("inserting into row\n");
          for(col=0;col<11;col++){
             printf("insterting into col\n");
             printf("getting from file\n");
             dump = (char *)fgetc(fileptr);
             printf("inserting in the space\n");
             maze[row][col]=atoi(dump);
          }
       }
    }

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    atoi() needs a char array, not a single char.

    Have a read of this . I'd suggest you concentrate on "option 1" in the text,
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  3. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  4. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  5. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM