I am teaching myself C, and feel like I am just starting to get the hang of pointers and arrays (I come from Python, where everything is magic). I'm looking for reviews, especially if I'm doing anything wrong. In this code I wrote my own strcat()
function, though it needs 3 args instead of the standard 2 (I couldn't figure out how to do it with just 2 without overrunning allotted memory).
#include <stdio.h>
#include <string.h>
char* cat(char *dest, char *a, char*b)
{
int len_a = strlen(a);
int len_b = strlen(b);
int i;
for(i = 0; i < len_a; i++)
{
dest[i] = a[i];
}
puts("");
int j;
for(j = 0;j < len_b; i++, j++)
{
dest[i] = b[j];
}
dest[i] = '\0';
puts("FUNCTION FINISHED");
}
int main()
{
char strA[] = "I am a small ";
char strB[] = "cat with whiskers.";
char strC[strlen(strA) + strlen(strB) + 1];
printf("length A: %lu, B: %lu, C: %lu\n", strlen(strA), strlen(strB), strlen(strC));
printf("sizeof A: %lu, B: %lu, C: %lu\n", sizeof(strA), sizeof(strB), sizeof(strC));
printf("A: '%s'\nB: '%s'\n", strA, strB);
cat(strC, strA, strB);
printf("c: '%s'\n", strC);
printf("length A: %lu, B: %lu, C: %lu\n", strlen(strA), strlen(strB), strlen(strC));
return 0;
}