943,312 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 5936
  • C RSS
Nov 1st, 2003
0

Reading a few chars from FileStream

Expand Post »
I have a simple program that has retreived the first number of a 12 number set from a text file. I am trying to convert this character array into a double or float so I can work with it, but none of the conversions are working. Anyone have any suggestions how I can do this? My code is posted below.

  1. String * strFilename = "c:/points";
  2. __wchar_t chrCoords __gc[] = new __wchar_t __gc[5];
  3. if (!File::Exists(strFilename))
  4. {
  5. Console::WriteLine(S"File not found. Exiting...");
  6. return -1;
  7. }
  8.  
  9. try
  10. {
  11. FileStream* fs = new FileStream(strFilename, FileMode::Open);
  12. StreamReader* sr = new StreamReader(fs);
  13.  
  14. sr->ReadBlock(chrCoords, 1, 4);
  15. Console::WriteLine(chrCoords);
  16. float fltX = chrCoords;
  17. Console::WriteLine(fltX);
  18. }
  19. catch(System::Exception* ExErr)
  20. {
  21. Console::WriteLine(ExErr->ToString());
  22. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Daywalker46410 is offline Offline
6 posts
since Sep 2003
Nov 1st, 2003
0

Re: Reading a few chars from FileStream

um.. are you using C# or something? Anyways in C stdlib library there is a function that can do what you want.
sscanf() the name is.
An example of its use would be
sscanf (string,"%f",float); It will take the first float from the string provided on the left and put its value into the float variable provided on the right.
Reputation Points: 13
Solved Threads: 0
Junior Poster in Training
Valmian is offline Offline
82 posts
since Sep 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: hm.. wiered..
Next Thread in C Forum Timeline: Locality





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC