0

I'm trying to keep concatenating the largeVal with smallVal when input a, and store the result into arr[] array.

int driver()
{
    char buffer[MAXLINE];
    char reply[MAXLINE * 1000];
    char largeVal[MAXLINE] =
        "a1b2c3d4e5f6g7h8i9j10a1b2c3d4e5f6g7h8i9j10a1b2c3d4e5f6g7h8i9j10a1b2c3d4e5f6g7h8i9j10a1b2c3d4e5f6g7h8i9j10a1b2c3d4e5f6g7h8i9j10a1b2c3d4e5f6g7h8i9j10a1b2c3d4e5f6g7h8i9j10";
    char smallVal[MAXLINE] = "5";

    while (strcmp(buffer,"a") == 0)
    {
        arr[MAXLINE * 1000] = strcat(smallVal, largeVal);
    }
    return foo(buffer, reply);
}

The error message is the following:

warning: assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion]

   91 |         arr[MAXLINE * 1000] = strcat(smallReply, largeReply);
      |                               ^

How should I fix this?

1
  • What do you mean, "when input a"? buffer is uninitialized and nothing ever modifies it. There's no user input or anything. Commented Jul 8, 2022 at 19:58

2 Answers 2

0

In the line

arr[MAXLINE * 1000] = strcat(smallVal, largeVal);

there are two issues. First, you are not assigning the string to arr, but trying to access the element in position [MAXLINE * 1000], which, in turn is just a plain char. Second, strcat returns an pointer to a char (array), i.e.: char *. So, you are trying to assign a pointer in a place that expects a value.

Sign up to request clarification or add additional context in comments.

Comments

0

The compiler message is clear enough. In this assignment statement

arr[MAXLINE * 1000] = strcat(smallVal, largeVal);

the left operand has the type char while the right operand has the type char * (the return type of the function strcat). So the statement does not make a sense.

It seems you mean something like the following

strcpy( arr, strcat(smallVal, largeVal) );

Pay attention to that the array smallVal should be large enough to store the appended string from the array largeVal.

Also this while loop

while (strcmp(buffer,"a") == 0)
{
    arr[MAXLINE * 1000] = strcat(smallVal, largeVal);
}

in any case invokes undefined behavior because the local array buffer is uninitialized.

char buffer[MAXLINE];

And moreover even if the array buffer will be initialized by the string "a" the loop will be infinite.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.