Search code examples
cvisual-studio-codec-stringsstrcat

I keep receiving this exception - Exception has occurred. EXC_BREAKPOINT (code=1, subcode=0x1b8c50bb0)


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

int main()
{
    char first[] = "This is the first part of";
    char second[] = "the full string, this being the second half\n.";
    char buffer[70];
    strcpy(buffer,first);
    strcat(buffer,second);
    puts(buffer);
    return 0;
}

I am receiving the error on strcat function, please assist enter image description here


Solution

  • It seems that the size of the array buffer is not large enough to contain the concatenated strings.

    Declare it at least like

    char first[] = "This is the first part of";
    char second[] = "the full string, this being the second half\n.";
    char buffer[sizeof( first ) + sizeof( second ) - 1];