Click here to Skip to main content
15,912,897 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionUpdating resource in yourself Pin
LiveShell31-Oct-07 22:06
LiveShell31-Oct-07 22:06 
AnswerRe: Updating resource in yourself Pin
Paresh Chitte31-Oct-07 22:39
Paresh Chitte31-Oct-07 22:39 
GeneralRe: Updating resource in yourself Pin
LiveShell31-Oct-07 23:10
LiveShell31-Oct-07 23:10 
QuestionNoob need help in c pro.. Pin
cue_ball31-Oct-07 21:54
cue_ball31-Oct-07 21:54 
AnswerRe: Noob need help in c pro.. Pin
cue_ball31-Oct-07 21:58
cue_ball31-Oct-07 21:58 
AnswerRe: Noob need help in c pro.. Pin
John R. Shaw31-Oct-07 22:20
John R. Shaw31-Oct-07 22:20 
GeneralRe: Noob need help in c pro.. Pin
cue_ball31-Oct-07 22:33
cue_ball31-Oct-07 22:33 
GeneralRe: Noob need help in c pro.. Pin
John R. Shaw1-Nov-07 12:50
John R. Shaw1-Nov-07 12:50 
Looks like ‘Iain Clarke’ gave a reasonable answer to your problem.

As for using structure/record type of format, you would have to place some restrictions on the field sizes, as you have discovered. But since you are dealing with a ‘.txt’ file, attempting to read it using a structure would be a bad idea, as it does not meet the requirement of structured data. Unstructured text data, in the form you presented, should probably be read one line at a time (kind of slow), parsed, and stored internally in any form you wish, including an array of records/structures.

The following is just for my entertainment, but it may give you some ideas:
enum my_field_sizes { REC_NSIZE=32, REC_IDSIZE=10, REC_PWSIZE=12};
typedef struct my_record
{
    char name[REC_NSIZE], id[REC_IDSIZE], pw[REC_PWSIZE];
} MY_RECORD;

const char* My_ReadField(const char* pStr, char* pOut, unsigned nOutSize)
{
    /* validate arguments */
    if( pStr && *pStr && pOut && nOutSize )
    {
        int i;
        /* skip any leading white space */
        while( isspace(*pStr) )
            ++pStr;
         /* read until a space is found, or pOut is full, or end of pStr is reached */
        for( i=0; i < nOutSize && !isspace(*pStr) && *pStr; ++i, ++pStr )
            pOut[i] = *pStr;
        i = (i < nOutSize) ? i : (nOutSize-1); /* safety first ;-) */
        pOut[i] = ‘\0’; /* end of string */
        /* make sure we have reached the delimiter (space) before returning */
        while( !isspace(*pStr) && *pStr )
            ++pStr;
    }
    return(pStr); /* pointer to next read position, end of pStr, or NULL */
}

void My_ReadRecordLine(MY_RECORD* pRec, const char* pLine)
{
    const char* pNextField = pLine;
    memset(pRec, 0, sizeof(MY_RECORD)); /* clear record first */
    pNextField = My_ReadField(pNextField, pRec->name, REC_NSIZE);
    pNextField = My_ReadField(pNextField, pRec->id, REC_IDSIZE);
    My_ReadField(pNextField, pRec->pw, REC_PWSIZE);
}



INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

AnswerRe: Noob need help in c pro.. Pin
Iain Clarke, Warrior Programmer1-Nov-07 2:26
Iain Clarke, Warrior Programmer1-Nov-07 2:26 
GeneralRe: Noob need help in c pro.. Pin
Robert Surtees1-Nov-07 14:40
Robert Surtees1-Nov-07 14:40 
AnswerRe: Noob need help in c pro.. Pin
Vijjuuu.1-Nov-07 2:43
Vijjuuu.1-Nov-07 2:43 
AnswerRe: Noob need help in c pro.. Pin
David Crow1-Nov-07 3:21
David Crow1-Nov-07 3:21 
QuestionHow to get a device's firmware Serial Number? Pin
kcynic31-Oct-07 21:07
kcynic31-Oct-07 21:07 
AnswerRe: How to get a device's firmware Serial Number? Pin
codn1-Nov-07 1:04
codn1-Nov-07 1:04 
QuestionAbout CImageList Pin
fantasy121531-Oct-07 20:40
fantasy121531-Oct-07 20:40 
AnswerRe: About CImageList Pin
Naveen31-Oct-07 20:51
Naveen31-Oct-07 20:51 
AnswerRe: About CImageList Pin
Hamid_RT31-Oct-07 21:02
Hamid_RT31-Oct-07 21:02 
QuestionRe: About CImageList Pin
fantasy121531-Oct-07 21:46
fantasy121531-Oct-07 21:46 
AnswerRe: About CImageList Pin
Hamid_RT1-Nov-07 1:07
Hamid_RT1-Nov-07 1:07 
Question[Message Deleted] Pin
purplee8531-Oct-07 19:57
purplee8531-Oct-07 19:57 
AnswerRe: GDIPLUS.h Pin
Naveen31-Oct-07 20:22
Naveen31-Oct-07 20:22 
AnswerRe: GDIPLUS.h Pin
Hamid_RT31-Oct-07 21:02
Hamid_RT31-Oct-07 21:02 
AnswerRe: [Message Deleted] Pin
ThatsAlok1-Nov-07 0:16
ThatsAlok1-Nov-07 0:16 
QuestionRe: [Message Deleted] Pin
Hamid_RT1-Nov-07 1:09
Hamid_RT1-Nov-07 1:09 
QuestionHow to include omnithread in my application? Pin
ashishbhatt31-Oct-07 19:45
ashishbhatt31-Oct-07 19:45 

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.