By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

I want to write a c program opening text file containing data and convert in matrix

P: 1
I want to write a c program which uses a text file containing 2 columns,
Using fopen() I opened the file but how to seperate the both columns in seperate arrays?
Sep 1 '10 #1
Share this Question
Share on Google+
1 Reply


P: 39
Read 1 line using fread.
sscanf the line into the 2 arrays.
make sure you use the right format in sscanf.

sscanf ( readbytes, "<right format>", &array1[i],&array2[i] )
example:
Expand|Select|Wrap|Line Numbers
  1. char* str = "134;123";
  2. int a[1],b[1];
  3. sscanf(str,"%d;%d",&a[0],&b[0]);
(ps: dont forget the fclose)
Sep 1 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.