| | |
Reading a few chars from FileStream
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2003
Posts: 6
Reputation:
Solved Threads: 0
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.
C Syntax (Toggle Plain Text)
String * strFilename = "c:/points"; __wchar_t chrCoords __gc[] = new __wchar_t __gc[5]; if (!File::Exists(strFilename)) { Console::WriteLine(S"File not found. Exiting..."); return -1; } try { FileStream* fs = new FileStream(strFilename, FileMode::Open); StreamReader* sr = new StreamReader(fs); sr->ReadBlock(chrCoords, 1, 4); Console::WriteLine(chrCoords); float fltX = chrCoords; Console::WriteLine(fltX); } catch(System::Exception* ExErr) { Console::WriteLine(ExErr->ToString()); }
•
•
Join Date: Sep 2003
Posts: 81
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- StreamReader and Position (C#)
- Counting the number of a specific word in a sentence? (Java)
- problems with reading random access line from a file (C++)
- c++ help function call (C++)
- storing file from a FileUpload control to a database (C#)
- Is there have any errors? (C)
- While loop not ending when reading from file (C++)
- Requesting Debugging Knowledge (C#)
Other Threads in the C Forum
- Previous Thread: hm.. wiered..
- Next Thread: Locality
| Thread Tools | Search this Thread |
* ansi append array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions test testautomation testing threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





