Menu

Constructing Floats.. Reading from input file

2008-10-28
2013-06-04
  • Nobody/Anonymous

    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/Anonymous

       
    • Nobody/Anonymous

      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;)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.