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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with strcat 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I want to concatenate an integer at the end of a string.

I am doing like this

int a=7;
char abc[50]="c:\\errorlog\\";
strcat(abc,((char*)a));
strcat(abc,"file.java");

This code doesn't give a error while compiling ,But gives a runtime error.

Kindly help me ..

 
you can do this by using "itoa()" function. this will convert your integer to string and then you can concat the resulted string with another string.
 
int a=7;
char* xx[2]=0;
xx[0]=(char)a+'0';
char abc[50]="c:\\errorlog\\";
strcat(abc,xx);
strcat(abc,"file.java");
John Fill
1c.bmp


ivfmd@mail.md
 
Yes your problem is in the 7. While using the
strcat(abc,((char*)a)); the 7 will be considered as an address and strcat function will start to read characters form the address 7 and all the problems.

 
i agree with rbobbit, sprintf is the best way to go. it's very simple and only one line of code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top