I'm an amateur programmer, bare with me:
I am trying to write my own strcat() function and testing it. Here is the code:
Code:
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int stringcat(char *s, char *t);
int main(void) {
char *ptr1;
char *ptr2;
ptr1 = (char *)malloc(20 * sizeof(char));
ptr2 = (char *)malloc(20 * sizeof(char));
char message1[] = "Please ";
char message2[] = "Reconsider\n";
strcpy(ptr1, message1);
strcpy(ptr2, message2);
stringcat(ptr1, ptr2);
while (*ptr1 != '\0')
printf("%c", *ptr1++);
free(ptr1);
free(ptr2);
return 0;
}
/* Copies string T to the end of string S */
int stringcat(char *s, char *t)
{
while (*s++ != '\0')
;
*s--;
while ((*s++ = *t++) != '\0')
;
*s = '\0';
return 0;
}
I keep getting a parse error around the place where I declare/initialize the arrays (message1 & message2).
Can anybody help me with this? The code looks fine!