Hello,

As you can see from my last threads, I need to some casting on char *,

InOrder to do it I use both std:string and also functions that work on char * (for example atoi)

together it looks like a mess and is not very efficent, so therefore I attach part of my code here, and I'll be happy to get advice of how to improve both efficiency and the way the code looks like (but not on efficency expence...)

Thanks in advance:
please note the following:

1. MyStdList is defined like that:

typedef std::list<myStruct*> MyStdList;

2.and myStruct is defined like that:

struct myStruct
{
int nItemNum;
char* pszItemData;
};

3. FormatMyString function is defined like that:
FormatMyString(string& str,int iStringLen);

and it trims the string and add zeros at the begining if string.length is shorter that iStrLen

4. I can't control pszItemData, I get it from another prcosses which determins how it is composed of (meaning first 5 chars are id for example)

so here is my function:

void BuildStr(MyStdList* pList,string& szOutputStr)
{
string sTmpStr;
string sStrHeader= "There are"

char szSizeOfList[6],szLZeroSizeOfList[6];
//szLZeroSizeOfList is szSizeOfList with leading zeros if
//necessary
itoa((int)pList->size(),szSizeOfList[,10);
sprintf(szLZeroSizeOfList,"%05s",szSizeOfList);

sStrHeader+= szLZeroSizeOfList;
sStrHeader += "items in the list";

for(MyStdList::iterator it = pList->begin(); it != pList->end(); it++)
{
myStruct *pMS = (myStruct*)*it;
string sMyItemData = pMS->pszItemData;

sTmpStr+= "Student ID is:";
string sTmp = sMyItemData.substr(0,5);
//student ID compose of first 5 digits
int iStudentID = atoi(sTmp.c_str());
//need iStudentID for later
FormatMyString(sTmp,5);

sTmpStr+= sTmp + "Student Name is:";
sTmp = sMyItemData.substr(5,30);


sTmpStr+= sTmp + "student age is:";
sTmp = sMyItemData.substr(30,33);

if(iStudentID<10000)
sTmpStr+= "This student started before year 2000";
else
sTmpStr+= "This student started in or after year 2000";

sTmp = sMyItemData.substr(33,15);
if(sTmp[14]>= 0 && sTmp[14] <= 0)
//last char in sTmp is numeric
//means this student is on scholership
{
int iScholershipSum = atoi(sTmp.c_str());
iScholershipSum = iScholershipSum/100;
//convert from cents to $$
char szScholershipSum[15];
itoa(iScholershipSum ,szScholershipSum,10);
sTmpStr+= "This student got scholarship, of";
sTmpStr+= szScholershipSum;
}
else
sTmpStr+= "This student didn't get scholarship";

}//end loop
szOutputStr = sStrHeader + sTmpStr;
}

the function is defined like that:

void BuildStr(MyStdList* pList,string& szOutputStr);

and I call it like that:

string szMyStr;
BuildStr(&List,szMyStr);


Thanks again
avi123