Author Topic: Constructing Floats.. Reading from input file  (Read 20142 times)

nobody

  • Guest
Constructing Floats.. Reading from input file
« on: October 28, 2008, 01:39:04 AM »
How would I got about reading a set of integers, floats, and strings as ASCII characters from an input file? THere is one entry per line and the first line in the file says how many entries there are.
Afterwards, we must determine what type of entry has been 'read' (int, float, or string) and depending on the type, we must create 3 different files and store each respective type on each file. We CANNOT use fscanf to read the entries... we must use the floating point assembly instruction to help with the conversion.

My main concern is about distinguishing the kind of type being read and how to read the entries without using fscanf! Anyone has any ideas? I've heard it's best to read everything as floats and make the determination of each type afterward.

nobody

  • Guest

nobody

  • Guest
Re: Constructing Floats.. Reading from input file
« Reply #2 on: October 28, 2008, 10:54:33 AM »
if you have for example the following list: 1.2 534 word (float, integer and string)
then it's easy to distinguish, you just read each byte separately and check if there is a dot between the numbers.
so it's not hard to distinguish between float and integer.
And string is not hard either.
i assume that your strings contain at least on byte that isn't a number (!123 or just a word: hello)
then you just make a function where you compare if bytes are different than numbers. If bytes in a string are all numbers and strings is meant to be a string then you can't distinguish unless mby lentgh or some other thing.

Oliver;)