473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to read the file given below in C and print the numbers in an array?

Hi all,

My file has characters and numbers in the format given below:

#
1
2
3
4
5
#
7
10
0
-5
8

I would like to read this file in C. Now everytime '#' appears it has to read the numbers below '#' and put them in an array say x[i][j]. It should increment 'j' everytime the program comes across an integer in the file. Everytime it comes across a '#', it has to make j=0; and increment 'i' by 1. For the input given above using a file, the numbers should be put in an array as given below:

#
1 i=0 j=0
2 i=0 j=1
3 i=0 j=2
4 i=0 j=3
5 i=0 j=4
#
7 i=1 j=0
10 i=1 j=1
0 i=1 j=2
-5 i=1 j=3
8 i=1 j=4

Thanks in advance for your replies!!!
Jul 19 '10 #1
3 1594
gpraghuram
1,275 Expert 1GB
Have you started writing anything for this?
We can help you with ideas and not code.

Raghu
Jul 20 '10 #2
@gpraghuram
yes, i have been able to write the code for sigle row of data following '#' . I am facing difficulty in several such series of rows.

Aeroranger
Jul 20 '10 #3
donbock
2,426 Expert 2GB
I don't know what your difficulties are, but perhaps it would help to take a look at Arrays Revealed.
Jul 20 '10 #4

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

Similar topics

5
by: deko | last post by:
I have a text file ("eighty.txt") that looks like this: 83|84|85|86 I can read the file into an array like this: $numbers= file("eighty.txt"); But how do I key the array? I'd like to use...
1
by: Stephen | last post by:
I have two arrays: int array1 = { { 1, 2, 3 }, { 4, 5, 6 } }; int array2 = { { 1, 2 }, { 3 }, { 4, 5, 6 } }; I need to print both of them by column like this:
4
by: Shailesh | last post by:
Hi! I want to overload << operator so that it can print an arry defined in MyClass.My problem is that I want to print only a no of elements NOT all the elements in the array and this no of...
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
15
by: Shuch | last post by:
Hi all, i m trying to read from a file and then copy it into an array...my code is as follow..it runs fine but i cant understand y it doesnt show me any output?? here is my code... using...
4
by: pariub | last post by:
So here is my problem once... i have a file called network.txt ...its a 13X13 matrix...but the network.txt can go up to 100X 100. I should read the text file and store it in array . ...
12
by: begum | last post by:
in this program they want me to find the max value of a subsequence in a given sequnce of numbers(the sequence is represented by an array) by using templates and pointers.also i must write a main...
6
by: Kinbote | last post by:
Hi, I'm trying to make a function that opens a file, reads it in line by line, puts each line into an malloc'd array, and returns the array. I suspect I'm going about it in an atypical fashion, as...
7
by: mathanne | last post by:
hi, I need help in creating a void function that read from a file into a two dimensional array. I'm ok when I create the function declaration but it gets confusing when I need to put the actual read...
2
by: tuananh87vn | last post by:
Hi ! can anyone help me with the following topic: Find All Duplicates in a List of Numbers - Array implementation - -InitializeTree() -AddNode() -Add into...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.