casting error arising upon appending a string to another one

I am trying to append a certain string (characters array) to another one as suggested here:,because%20the%20given%20literal%20string%20cannot%20be%20modified

My code is as follows:

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

int main(){

char *mystring="Life";
int length_string=strlen(mystring);

char *string_continuation=" is life";
int length_continuation=strlen(string_continuation);

char *new_word=malloc(length_string+length_continuation+1);

for (int i=0; i<length_string; i++){


printf("The final word is %s", new_word);
free (new_word);

return 0;

However, I am getting the typical error:

assignment makes integer from pointer without a cast [-Wint-conversion]

which refers to line:


Does anyone know why such error arises? Many thanks

1 answer

  • answered 2021-07-23 10:28 Vlad from Moscow

    In this assignment statement


    the right operand of the assignment is string literal "\0" that has the type char[2] and is implicitly converted in the expression to the type char *.

    On the other hand, the left operand has the type char. So the compiler issues the error.

    You need to write


    using integer character constant '\0'.

    Pay attention that there is a typo in the for loop. Instead of

    for (int i=0; i<length_string; i++){

    there must be

    for (int i=0; i<length_continuation; i++){

    Also instead of the for loop you could just use the standard C function strcat as for example

    strcat( new_word, string_continuation );

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum