P
Polar
Hi!
i'm a newbie in C language and i'm writing my first simple codes.
In one of these, my purpose is to append the ascii value of an interger
(example 101 --> e) at the end of a string to obtain a new (longer)
string. Example:
string: languag
letter: e
string (new value): language
In compiling, i received "Segmentation fault" error but i
can't understand why.
This is the very simple code:
main()
{
char* output="languag";
int i = 101;
char* letter;
letter[0]=(char)i;
letter[1]='\0';
printf("%s\n",letter); //prints "e"
//next line is not executed
strcat(output,letter); //segmentation fault printf("%s\n",output);
}
Thank you
i'm a newbie in C language and i'm writing my first simple codes.
In one of these, my purpose is to append the ascii value of an interger
(example 101 --> e) at the end of a string to obtain a new (longer)
string. Example:
string: languag
letter: e
string (new value): language
In compiling, i received "Segmentation fault" error but i
can't understand why.
This is the very simple code:
main()
{
char* output="languag";
int i = 101;
char* letter;
letter[0]=(char)i;
letter[1]='\0';
printf("%s\n",letter); //prints "e"
//next line is not executed
strcat(output,letter); //segmentation fault printf("%s\n",output);
}
Thank you