Click here to Skip to main content
15,917,997 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Machine Identification Pin
Bram van Kampen7-Jan-08 16:53
Bram van Kampen7-Jan-08 16:53 
GeneralRe: Machine Identification Pin
Naveen7-Jan-08 17:25
Naveen7-Jan-08 17:25 
GeneralRe: Machine Identification Pin
Hamid_RT7-Jan-08 18:10
Hamid_RT7-Jan-08 18:10 
Questionhow to read a data file from harddis to program? Pin
gentleguy7-Jan-08 14:26
gentleguy7-Jan-08 14:26 
AnswerRe: how to read a data file from harddis to program? Pin
wira1guys7-Jan-08 14:41
wira1guys7-Jan-08 14:41 
GeneralRe: how to read a data file from harddis to program? [modified] Pin
gentleguy7-Jan-08 15:53
gentleguy7-Jan-08 15:53 
GeneralRe: how to read a data file from harddis to program? Pin
Maxwell Chen7-Jan-08 16:36
Maxwell Chen7-Jan-08 16:36 
GeneralRe: how to read a data file from harddis to program? Pin
Bram van Kampen7-Jan-08 16:43
Bram van Kampen7-Jan-08 16:43 
Without further info I do not realy understand your problem, but, the general procedure is:

Step 1. You should know the fully qualified name of the file you want to read i.e.: CString MyFile="C:\MyDirectory\MyData\DataFile.ext". If you type that as a string in your code(bad Idea, but not your immediate problem) you should type all backslashes double. i.e.:CString MyFile="C:\\MyDirectory\\MyData\\DataFile.ext".

Step 2;

You Open the file, and get a File Handle:

FILE* F =fopen(MyFile,"rb"); The "rb" means that you want to open the file for binary reading, (as opposed to Text Reading, which should be opened for reading with just "r")
Step 3: You find out how big the file is. You move the File Pointer to the End of the File, and ask where it is.

size_t CurPos=ftell(F);// Record the File Pointer
fseek(F,0,SEEK_END)
size_t FileSize=ftell(F);
fseek(F,CurPos,SEEK_SET);// Returns the FilePointer to where it was


Step 4:
Allocate a buffer to hold the File Contents
char* Buf=(char*)malloc(FileSize);

Step 5:

Ensure that there was enough free memory left to Allocate the Buffer

if(Buf==NULL) return ERR_OUT_OF_MEM;

Step 6:

Read the File into the Buffer
fread(Buf,FileSize,sizeof(char),F);

step 7:

Close the File. This is most important, Noone Else can work with the file while you have it open, Even yourself cannot open it a second time.

Step 8:

The contents of your file is now in Buf. Do with it as you like.

Step 9:

When You're done with it, you should 'free' Buf. Unlike say VB, C++ has NO garbage collection service. It is up to you to get rid of memory you no longer need.

Smile | :) Smile | :)

Bram van Kampen

GeneralRe: how to read a data file from harddis to program? Pin
gentleguy7-Jan-08 19:46
gentleguy7-Jan-08 19:46 
AnswerRe: how to read a data file from harddis to program? Pin
Hamid_RT7-Jan-08 18:03
Hamid_RT7-Jan-08 18:03 
GeneralRe: how to read a data file from harddisk to program and print it on the screen? Pin
gentleguy7-Jan-08 19:47
gentleguy7-Jan-08 19:47 
Generalcoding for x and y coordinates detection Pin
student867-Jan-08 14:09
student867-Jan-08 14:09 
QuestionRe: coding for x and y coordinates detection Pin
Mark Salsbery7-Jan-08 14:19
Mark Salsbery7-Jan-08 14:19 
GeneralRe: coding for x and y coordinates detection Pin
student867-Jan-08 14:26
student867-Jan-08 14:26 
GeneralRe: coding for x and y coordinates detection Pin
Mark Salsbery7-Jan-08 14:36
Mark Salsbery7-Jan-08 14:36 
GeneralRe: coding for x and y coordinates detection Pin
student867-Jan-08 14:49
student867-Jan-08 14:49 
GeneralRe: coding for x and y coordinates detection Pin
Mark Salsbery7-Jan-08 15:10
Mark Salsbery7-Jan-08 15:10 
QuestionHow to use the same class for two dialogs? (avoiding IDD clash...) Pin
@largeinsd7-Jan-08 12:00
@largeinsd7-Jan-08 12:00 
AnswerRe: How to use the same class for two dialogs? (avoiding IDD clash...) Pin
Mark Salsbery7-Jan-08 13:03
Mark Salsbery7-Jan-08 13:03 
GeneralRe: How to use the same class for two dialogs? (avoiding IDD clash...) Pin
@largeinsd7-Jan-08 13:18
@largeinsd7-Jan-08 13:18 
GeneralRe: How to use the same class for two dialogs? (avoiding IDD clash...) Pin
Maxwell Chen7-Jan-08 21:18
Maxwell Chen7-Jan-08 21:18 
GeneralRe: How to use the same class for two dialogs? (avoiding IDD clash...) Pin
Mark Salsbery8-Jan-08 9:29
Mark Salsbery8-Jan-08 9:29 
GeneralRe: How to use the same class for two dialogs? (avoiding IDD clash...) Pin
Maxwell Chen8-Jan-08 16:07
Maxwell Chen8-Jan-08 16:07 
GeneralRe: How to use the same class for two dialogs? (avoiding IDD clash...) Pin
Mark Salsbery9-Jan-08 6:35
Mark Salsbery9-Jan-08 6:35 
Questionhow cai i get cpu temperature without wmi Pin
lgbean7-Jan-08 10:32
lgbean7-Jan-08 10:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.