#include #include char *s1 = "This is a long string. Even more than one sentence!"; int strLength(char *string) { int length = 0; while(*string != '\0'){ string++; // string = string +1; length++; } return length; } char * mystrcpy ( char * destination, const char * source) { int k; k = 0; while( source[k] != '\0' ){ destination[k] = source[k]; //*(destination + k) = *(source+k); k++; } destination[k] = '\0'; return destination; } void myStrInverter(char* start) { char *end, tmp; // räkna ut pekaren till sista tecknet (ej null) end = start; while(*end){ end++; } end--; // swappa ett tecken while(end > start){ tmp = *end; *end = *start; *start = tmp; start++; end--; } } int main(int argc, char **argv) { char* myString2; int length = strLength(s1); myString2 = (char*)malloc((length+1)*sizeof(char)); myString2 = mystrcpy(myString2, s1); myStrInverter(myString2); printf("The length of s1 was %i\n", length); printf("s1: %s\n", s1); printf("myString2: %s\n", myString2); printf("hello world\n"); return 0; }