Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding to end of char array

Status
Not open for further replies.

BigDaz

Technical User
Jan 14, 2002
39
GB
Hello,

I wish to read in a string of chars into a char array then add a carriage return and a line feed to the end then send it elsewhere; i'm trying to do it in the following manner:

char cMess[32] = {0};
GetDlgItemText ( IDC_EDIT1, cCom, 32);

int iLen = strlen( cCom );

cCom[iLen] = (char)(13); // carriage return
cCom[iLen+1] = (char)(10); // line feed

sendstuff( cCom, iLen+2 );

the problem is it doesn't seem to work, could anyone please offer any advice?

Thanks, BigDaz.
 
1. cMess or cCom?
2. int iLen = GetDlgItemText(...) - it returns number of bytes (no need to invoke strlen();).
3. Use = '\r', = '\n' (C chars for CR LF)
4. add null byte to terminate your string...
 
You might want to declare your array as length 35 in case the GetDlgItemText fills up all 32 bytes you requested. That way you can still fit the carriage return, line feed, and NULL character.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top