kilter wrote:

Nils O. Selåsdal wrote:
>kilter wrote:
>>Anyone know of a routine that will return the number of rows and

columns in a matrix?

As C has no matrices, you should explain further what you mean

and want.

Thanks for your quick reply. The idea is that I open a file that has

numerical data in a form of a matrix but I don't know a priori the

number of columns and rows of this file. I want to know the number of

rows and columns of that data matrix, after I read it and store it as a

matrix in C, in order to apply operations to its entries.

I am a novice really and your help is very much appreciated.

Thank you

It depends. If the numerical data is actually stored as a (ascii or

similar) matrix, and each value is separated by spaces, tabs, what have

you, and rows are written line by line you read in one number at a time,

keep track and signal the EOL.

If it's in some binary/structured form you probably want to read in a

structure like that all at once.

If it's just a consecutive row of numbers in a flat file, you may have

to look for delimiter values in the data ending each row, and if these

aren't there you can't be sure how the matrix looks like, as long as

their are multiple m,n where m * n satisfies the total count of numbers

read.

You could have a look at sscanf(), scanf() functions on how to read in

data in a formatted way. Maybe browsing the c-faq, in particular chapter

12

http://www.c-faq.com/stdio/index.html isn't such a bad idea, it must

have some useful stuff on reading in date from files (or basically any

data stream, as C treats them all the same)

For a good primer on C, Kernighan and Ritchie still is considered of

unparallelled value by many, I my self have learnt(ed?) a great deal of

(the little bit of) what I know from

http://publications.gbdirect.co.uk/c_book/
Pretty dated stuff, but clear, concise and to the point nonetheless.

HTH

Sh.