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!

Put Enter character !!!

Status
Not open for further replies.

HadiRezaee

Technical User
Mar 9, 2001
165
IR
Hi all.
I have string like "Hadi", i must put Enter character in end of my string : "Hadi" + Enter character.

char *szTemp = new char[10];
szTemp = "Hadi";
szTemp[5] = char(13);
szTemp[6] = '\0';

But this code won't work ...
Please help me ...
 
This is not quite right.

char *szTemp = new char[10]; // creates pointer to space
szTemp = "Hadi"; // allocates location of string defined not at your intended location should use strcpy or similar.

szTemp[5] = char(13);
szTemp[6] = char(10);
szTemp[7] = '\0';

The char(13) and char(10) is carriage return linefeed which
is generally used to infer a hard return (Enter).

Hope this helps sma.
 
There is a more elegant way to do this:

#include <string.h> //for strcat call
#define CRLF &quot;\x0d\x0a&quot; //13 and 10 in hexa

char *szTemp = new char[10];
szTemp = &quot;Hadi&quot;;
strcat(szTemp,CRLF);

Hope this helps,s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top