Reading a few chars from FileStream

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2003
Posts: 6
Reputation: Daywalker46410 is an unknown quantity at this point 
Solved Threads: 0
Daywalker46410 Daywalker46410 is offline Offline
Newbie Poster

Reading a few chars from FileStream

 
0
  #1
Nov 1st, 2003
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. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2003
Posts: 81
Reputation: Valmian is an unknown quantity at this point 
Solved Threads: 0
Valmian Valmian is offline Offline
Junior Poster in Training

Re: Reading a few chars from FileStream

 
0
  #2
Nov 1st, 2003
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC