Mmh in runtime continua a dirmi:
Errore di segmentazione (core dump creato)
Ecco tutto il file [main.c]
#include<stdio.h>
char *strcpy(char *, const char *);
char *strcat2(char *dest, const char *src);
int strcmp(char *str1, char *str2);
int strlen(const char *);
main(){
char *a = "Hello ", *b = "World!";
printf("[%s]\n", a);
printf("[%s]\n", b);
printf("Ris [%s]\n", strcat2(a,b));
return 0;
}
int strlen(const char *str){
int counter;
for(counter = 0; str[counter] != '\0'; counter++)
;
return counter;
}
int strcmp(char *str1, char *str2)
{
int count1, count2;
count1 = strlen(str1);
count2 = strlen(str2);
if(count1 < count2) return -1;
else if(count1 == count2) return 0;
else return 1;
}
char *strcat2(char *dest, const char *src)
{
char* temp = dest;
while(*dest)
dest++;
while( (*dest++ = *src++) )
;
return temp;
}
char *strcpy(char *dest, const char *src)
{
int i = 0;
for(i=0; dest[i] = src[i]; i++)
;
}
l'output del programma è:
spaccaversi@ubuntu:~/codici/c$ ./a.out
[Hello ]
[World!]
Errore di segmentazione (core dump creato)