Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proble solving - can someone help?

Status
Not open for further replies.

kjb

Technical User
Oct 24, 2000
11
0
0
CA
I am new to c programming. Could someone help me to solve the following problem related to arrays and text file:

A company has a large number of text files. These files are organized as follows:

1. the first line contains a threshold value.
2. the second line specifies the number of rows in the matrix.
3. the third line specifies the number of columns in the matrix.
4. each remaining line is one row of the matrix.

1.3
5
3
1.1 1.9 1.4
0.9 1.8 1.1
1.8 1.6 0.4
0.6 0.2 1.7
0.4 1.4 0.3

Assume no. of rows <=20, no. of columns <= 15.

Write a program that asks the user to supply the name of an input file, reads the data from input file, and prints the following info:
1. The treshold value
2. The numbers of rows and columns in the matrix
3. For each column the number of values in that column that are greater than or equal to threshold value.
4.the average of elements in the matrix

Help would be highly appreciated.
 
Post your attempt (i.e. the code) and describe the problems you're having with it and somebody will try to help you. This looks like a copy and pasted homework assignment.

Russ
bobbitts@hotmail.com
 
Thanks for your reply.

As I said, I am new to c programming. I have taught myself the basics in preparation for an exam but I have no clue how to tackle this problem. I know how to open an input file and am familiar with arrays. But need direction to get started on this. Could not find a similar problem in any of the text books I could get. Thx.
 
Do you know how to get user input? Do you at least have some skeleton code that opens a file and reads all the lines in the file? If so, post that.

A few hints: look into fgets() for user input and reading the file line by line, look into strtok() to parse the lines that contain the matrix values and strtof() or strtod() to convert the matrix values into numeric values.

Once you get some code together, post again.

HTH,



Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top