I just started leaning c programming, and i have been doing alright, but now am stuck with a problem, I do not know how to read information from a file in c. the file contains info like;
123456789123456789123456789123456789...and so on. i have to read the file in, and then group the numbers in the file into 7, make them a coulumn matrix and multipy each of the column matrix with another matrix. ive written the code to multiply two matrixs and it works, i just dont know how to group the numbers into groups of 7 and make them a colum matrix like below.
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
cesione 0 Newbie Poster
Recommended Answers
Jump to PostMost of the time "I don't know" is not an attenuation for lack of effort in this forum.
If you don't know, try to lean, and prove at least, what effort you have done in such endeavor. Anything else would be an aggravation against your cause.
Jump to Post>>123456789123456789123456789123456789
Does the file actually look like that -- just a bunch of numbers with no separation between them?
Jump to PostI would call fgets() instead of scanf() to read the entire file into a character array so that they can be rearranged or displayed (printed) however you wish.
Jump to PostHere is how to convert a digit in the string to an integer. Just subtract '0' from the digit to get the int value. Now put that in a loop to assign each character of the string into a matrix.
char str[] = "1010101";
int digit0 = str[0] - …
All 15 Replies
Aia 1,977 Nearly a Posting Maven
cesione 0 Newbie Poster
Aia 1,977 Nearly a Posting Maven
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Adak 419 Nearly a Posting Virtuoso
cesione 0 Newbie Poster
cesione 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
cesione 0 Newbie Poster
Adak 419 Nearly a Posting Virtuoso
cesione 0 Newbie Poster
cesione 0 Newbie Poster
cesione 0 Newbie Poster
Adak 419 Nearly a Posting Virtuoso
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.