Click here to Skip to main content
15,890,690 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Local static variable is thread safe? Pin
Manoj Kumar Rai21-May-07 19:55
professionalManoj Kumar Rai21-May-07 19:55 
AnswerRe: Local static variable is thread safe? Pin
Sameerkumar Namdeo21-May-07 20:11
Sameerkumar Namdeo21-May-07 20:11 
GeneralRe: Local static variable is thread safe? Pin
Best Kiluyar21-May-07 20:38
Best Kiluyar21-May-07 20:38 
GeneralRe: Local static variable is thread safe? Pin
Manoj Kumar Rai21-May-07 20:49
professionalManoj Kumar Rai21-May-07 20:49 
GeneralRe: Local static variable is thread safe? Pin
Best Kiluyar21-May-07 21:10
Best Kiluyar21-May-07 21:10 
GeneralRe: Local static variable is thread safe? Pin
rrrado21-May-07 22:26
rrrado21-May-07 22:26 
GeneralRe: Local static variable is thread safe? Pin
Best Kiluyar21-May-07 22:51
Best Kiluyar21-May-07 22:51 
Questionproblem with fread and char* Pin
dreamtwister21-May-07 19:10
dreamtwister21-May-07 19:10 
I'm trying to read a char* from a binary file. The data is written to the file correctly, but when I read it back, my string is appended with gibberish. Here's a snippit:

char* load_string(FILE* f)
{
    size_t len;
    char* str = NULL;
    fread(&len, sizeof(size_t), 1, f); /* this correctly returns # of bytes */
    if (len)
    {
        /* if not null */
        str=(char*)malloc(len);
        fread(str, sizeof(char), len, f);
    }
    else
    {
        /* null pointer */
        str=NULL;
    }
    return str;
}


And here is how I am using the function:

fopen_s(&f, "hi.dat", "rb"); /* open for reading */
if (f)
{
    szLoad = load_string(f);
    fclose(f);
}


I'm pretty sure it's a problem with malloc() allocating too much memory, because when I do a strlen(str) it returns as longer than expected, even though len is correctly interpreted from the file.

Any help would be greatly appreciated.
AnswerRe: problem with fread and char* Pin
User 58385221-May-07 19:57
User 58385221-May-07 19:57 
AnswerRe: problem with fread and char* Pin
led mike21-May-07 19:57
led mike21-May-07 19:57 
QuestionVideo recording on motion detection Pin
tyagineha21-May-07 18:18
tyagineha21-May-07 18:18 
QuestionFlickering - pls help me its urgent Pin
deeps_cute21-May-07 18:16
deeps_cute21-May-07 18:16 
AnswerRe: Flickering - pls help me its urgent Pin
baerten21-May-07 21:45
baerten21-May-07 21:45 
QuestionText file to excel Pin
ashost0721-May-07 17:27
ashost0721-May-07 17:27 
AnswerRe: Text file to excel Pin
Manoj Kumar Rai21-May-07 19:52
professionalManoj Kumar Rai21-May-07 19:52 
AnswerRe: Text file to excel Pin
Nelek21-May-07 20:04
protectorNelek21-May-07 20:04 
AnswerRe: Text file to excel Pin
Sameerkumar Namdeo21-May-07 20:38
Sameerkumar Namdeo21-May-07 20:38 
QuestionConjunctive Normal Form Code [URGENT] Pin
Star0921-May-07 16:22
Star0921-May-07 16:22 
AnswerRe: Conjunctive Normal Form Code [URGENT] Pin
led mike21-May-07 20:03
led mike21-May-07 20:03 
GeneralRe: Conjunctive Normal Form Code [URGENT] Pin
Rajesh R Subramanian21-May-07 20:42
professionalRajesh R Subramanian21-May-07 20:42 
GeneralRe: Conjunctive Normal Form Code [URGENT] Pin
Mark Salsbery22-May-07 4:23
Mark Salsbery22-May-07 4:23 
GeneralRe: Conjunctive Normal Form Code [URGENT] Pin
Rajesh R Subramanian22-May-07 6:57
professionalRajesh R Subramanian22-May-07 6:57 
QuestionDatabase Class in VC++ Pin
Programm3r21-May-07 9:08
Programm3r21-May-07 9:08 
AnswerRe: Database Class in VC++ Pin
led mike21-May-07 9:26
led mike21-May-07 9:26 
GeneralRe: Database Class in VC++ Pin
Programm3r21-May-07 20:35
Programm3r21-May-07 20:35 

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.