Hi i'm trying to concatenate two char and i keep getting core dumpped:

char *user = "name";
char *temp = "USER ";
strcat(temp, user);

if anybody knows what i'm doing wrong please let me know.

Thank u

Yes, you are trying to write to read-only memory. Create an array with enough space instead of trying to write to a string literal initializer.

[edit]

#include <stdio.h>
#include <string.h>

int main( void )
{
   char user[] = "name";
   char temp[ sizeof user + 5 ] = "USER ";
   strcat(temp, user);
   puts(temp);
   return 0;
}

/* my output
USER name
*/

but i don't know how much data i will recieve. and how do u do an array in c?

thank u

user = argv;
--------------------
char temp[sizeof(user) +5] = "USER ";//anonymous\r\n";
strcat(temp, user);
printf("%s\n", temp);


writeData(s, temp, strlen(temp)); //the function writeData has parameter char*temp
---------------------------------------------
void writeData(int s, char *d, int len)
{
int numChar;
while(len != 0)
{
numChar = write(s, d, len);


if(numChar == -1)
{
fputs("An error has occured in sending data",stderr);
exit(7);
}


len -= numChar;
d += numChar;


}
}

the program just freeze with this code

Edited 3 Years Ago by happygeek: fixed formatting

Thank you soooo much man, it is working. you have saved a lot of time for me.

I have another question: what does this warning means?
implicit declaration of function `read'

I have another question: what does this warning means?
implicit declaration of function `read'

You probably have a function called before a prototype is declared, or one that looks like this:

read(/*parameters*/);

rather than

int read(/*parameters*/); /* or other return type */
This article has been dead for over six months. Start a new discussion instead.