Click here to Skip to main content
16,005,552 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Parse CHAR pointers Pin
John R. Shaw2-Apr-04 12:11
John R. Shaw2-Apr-04 12:11 
GeneralRe: Parse CHAR pointers Pin
gUrM33T2-Apr-04 15:28
gUrM33T2-Apr-04 15:28 
GeneralRead Write ANSI/C Pin
gls2ro2-Apr-04 10:44
gls2ro2-Apr-04 10:44 
GeneralRe: Read Write ANSI/C Pin
Anonymous2-Apr-04 11:08
Anonymous2-Apr-04 11:08 
Generalchar ** problem (ANSI C) Pin
kfaday2-Apr-04 6:44
kfaday2-Apr-04 6:44 
GeneralRe: char ** problem (ANSI C) Pin
David Crow2-Apr-04 6:53
David Crow2-Apr-04 6:53 
GeneralRe: char ** problem (ANSI C) Pin
kfaday2-Apr-04 7:15
kfaday2-Apr-04 7:15 
GeneralRe: char ** problem (ANSI C) Pin
John R. Shaw2-Apr-04 10:09
John R. Shaw2-Apr-04 10:09 
// this is wrong in C or C++ (array is 1 short - will overwrite memory)
cantpalres=i-1;
palres = (char**) malloc ((sizeof(char*))*cantpalres); //is this ok???????????
// this is right (add toss the exta braces)
cantpalres=i;
palres = (char**) malloc (sizeof(char*)*cantpalres);

// 1st and 2nd part (simpified)

i=0;
while (!feof(archpalres))
{
    if( !fgets (temp,MAX_PAL,archpalres) )
        break;
    ++i; // i++ ok in C but a bad habit in C++
}
cantpalres=i;
// allocate 2 dimensional array of string/charater pointers
palres = (char**) malloc (sizeof(char*)*cantpalres);
if( !palres ) // always check if allocation succeded
    return; // or return some error value
fseek (archpalres,0,SEEK_SET);
i=0;
while (!feof(archpalres))
{
    if( !fgets (temp,MAX_PAL,archpalres) )
        break;
    // replace '\n' with '\0'
    pNewline = strchr(temp,'\n');
    if( pNewline ) // there might not be a newline after last word
        *pNewLine = '\0';
    len = strlen(temp) + 1; // +1 for '\0'
    // allocate array of charaters
    palres[i] = (char*) malloc (sizeof(char)*len);
    if( palres[i] ) // always check if allocation succeded
        strcpy(palres[i],temp);
    ++i;
}


Normaly I would not have given a complete solution, but there was to much wrong too explane it all.

INTP
GeneralRe: char ** problem (ANSI C) Pin
kfaday3-Apr-04 4:54
kfaday3-Apr-04 4:54 
GeneralRe: char ** problem (ANSI C) Pin
toothless boots2-Apr-04 13:19
toothless boots2-Apr-04 13:19 
GeneralGetting thread timing Pin
Brian R2-Apr-04 5:50
Brian R2-Apr-04 5:50 
GeneralRe: Getting thread timing Pin
Alexander M.,2-Apr-04 6:05
Alexander M.,2-Apr-04 6:05 
GeneralUnicode Pin
Simon Poon2-Apr-04 5:30
Simon Poon2-Apr-04 5:30 
GeneralRe: Unicode Pin
Alexander M.,2-Apr-04 6:03
Alexander M.,2-Apr-04 6:03 
GeneralRe: Unicode Pin
Simon Poon2-Apr-04 6:36
Simon Poon2-Apr-04 6:36 
GeneralRe: Unicode Pin
usfesco2-Apr-04 12:35
usfesco2-Apr-04 12:35 
GeneralTracking mouse moves in a ListView control Pin
srev2-Apr-04 4:44
srev2-Apr-04 4:44 
GeneralRe: Tracking mouse moves in a ListView control Pin
Mike Dimmick2-Apr-04 5:19
Mike Dimmick2-Apr-04 5:19 
GeneralRe: Tracking mouse moves in a ListView control Pin
srev3-Apr-04 5:34
srev3-Apr-04 5:34 
GeneralTape enter to change CEdit Focus Pin
amine.turki2-Apr-04 4:37
amine.turki2-Apr-04 4:37 
GeneralRe: Tape enter to change CEdit Focus Pin
David Crow2-Apr-04 4:57
David Crow2-Apr-04 4:57 
GeneralRe: Tape enter to change CEdit Focus Pin
amine.turki2-Apr-04 5:17
amine.turki2-Apr-04 5:17 
GeneralRe: Tape enter to change CEdit Focus Pin
David Crow2-Apr-04 5:23
David Crow2-Apr-04 5:23 
GeneralRe: Tape enter to change CEdit Focus Pin
Roger Allen2-Apr-04 5:46
Roger Allen2-Apr-04 5:46 
GeneralRe: Tap enter to change CEdit Focus Pin
Shog92-Apr-04 6:20
sitebuilderShog92-Apr-04 6:20 

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.