Click here to Skip to main content
15,913,836 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralStatic Redraw Pin
Shotgun8-Mar-03 11:03
Shotgun8-Mar-03 11:03 
QuestionHow to hide the web browser control Pin
Hesham Amin8-Mar-03 10:37
Hesham Amin8-Mar-03 10:37 
AnswerRe: How to hide the web browser control Pin
Nish Nishant8-Mar-03 10:49
sitebuilderNish Nishant8-Mar-03 10:49 
GeneralRe: How to hide the web browser control Pin
Hesham Amin8-Mar-03 11:13
Hesham Amin8-Mar-03 11:13 
QuestionExit code 136? Pin
Jason Henderson8-Mar-03 10:22
Jason Henderson8-Mar-03 10:22 
GeneralMessage routing Pin
AnTri8-Mar-03 6:57
AnTri8-Mar-03 6:57 
GeneralRe: Message routing Pin
Kuniva8-Mar-03 7:25
Kuniva8-Mar-03 7:25 
Generalfclose() error Pin
Kuniva8-Mar-03 6:00
Kuniva8-Mar-03 6:00 
Hi, i am writing a function to read in certain data from a file using stdio.h
but when i try to close the file handle with fclose() windows gives me the error "Myapp.exe has encountered a problem and needs to close. blablabla..."

This is the code:

FILE *npf;
char id[3];
float version;


if((npf = fopen(FileName, "rb")) == NULL)  // FileName is a global char with a valid file name
{
    fclose(npf);
    return FALSE;
}
if(fseek(npf, 0L, SEEK_SET))
{
    fclose(npf);
    return FALSE;
}

fscanf(npf, "%s", id);
//fscanf(npf, "%f", &version);

//char vers[10];
//sprintf(vers, "%f", version);


string IDs;
IDs.append(id);
//ID.append(" ");
//ID.append(vers);

MessageBox (NULL, IDs.c_str() , "ID", 0 + MB_ICONASTERISK);

fclose(npf); // <---- this is where i get my error from windows
return TRUE;


Also, you can see the lines i commented out where i try to read a float after reading the string, when i leave those in, i get the error at the line fscanf(npf, "%f", &version)
Can anyone tell me whats causing this? I looked at an example from the MSDN about file streams and i've worked with them before so i don't really see whats wrong here.

Thanks

P.S.: Yes, the file is big enough for the string and the float to be read.


Kuniva
--------------------------------------------
GeneralRe: fclose() error Pin
Chris Losinger8-Mar-03 6:43
professionalChris Losinger8-Mar-03 6:43 
GeneralRe: fclose() error Pin
Kuniva8-Mar-03 7:16
Kuniva8-Mar-03 7:16 
GeneralRe: fclose() error Pin
Chris Losinger8-Mar-03 8:28
professionalChris Losinger8-Mar-03 8:28 
GeneralRe: fclose() error Pin
Kuniva8-Mar-03 7:42
Kuniva8-Mar-03 7:42 
GeneralRe: fclose() error Pin
Tim Smith8-Mar-03 16:13
Tim Smith8-Mar-03 16:13 
GeneralRe: fclose() error Pin
Kuniva8-Mar-03 8:11
Kuniva8-Mar-03 8:11 
GeneralRe: fclose() error Pin
Abbas_Riazi8-Mar-03 18:04
professionalAbbas_Riazi8-Mar-03 18:04 
GeneralModifyStyle dynamically Pin
Gumball8-Mar-03 5:37
Gumball8-Mar-03 5:37 
GeneralSchool Project in C Pin
Claus Jobes8-Mar-03 4:58
Claus Jobes8-Mar-03 4:58 
GeneralRe: School Project in C Pin
dog_spawn8-Mar-03 6:58
dog_spawn8-Mar-03 6:58 
GeneralRe: School Project in C Pin
Claus Jobes8-Mar-03 7:05
Claus Jobes8-Mar-03 7:05 
GeneralRe: School Project in C Pin
yaname8-Mar-03 12:38
yaname8-Mar-03 12:38 
GeneralRe: School Project in C Pin
Claus Jobes8-Mar-03 15:06
Claus Jobes8-Mar-03 15:06 
QuestionHow to detect that cd rom drive is opened? Pin
Mukkie8-Mar-03 3:39
Mukkie8-Mar-03 3:39 
GeneralCProgressBar Pin
wavewave8-Mar-03 1:19
wavewave8-Mar-03 1:19 
GeneralRe: CProgressBar Pin
AnTri8-Mar-03 7:11
AnTri8-Mar-03 7:11 
GeneralRe: CProgressBar Pin
wavewave8-Mar-03 23:28
wavewave8-Mar-03 23:28 

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.