Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Assume the text file contains data as below:

I would like to convert it to multi-dimensional matrix in the form of matrix[i][j].I'm thinking of allocate array of pointers to arrays.
The problem now is how to convert the form as in the text file into matrix[i][j].
The row and column will change according to the data size.

The output that I'm looking for is something like this:
         0  1  2 (columns)
      0  1  2  4
(rows)1  2  1  5
      2  4  5  1

Note: if(i=j) matrix[i][j]=1
symmetrical: matrix[i][j] = matrix [j][i]
Updated 16-May-12 18:18pm

use file handling to fetch character by character data and you can store it in your multidimensional matrix..

have a look at this for retrieving data from file[^]

if you are reteiving data in character format and you want to store it in integer then you have to type cast it but i suppose according to your above shown example you must be using character array

Share this answer
Forget about using file input and figure out the algorithm to convert your "rules" to their matrix equivalent. You could simulate it by adding the above strings into your program and parsing them while you develop your algorithm. What value(s) determines the number of rows or colums? What are the ranges of values in each row or column? etc.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900