What is the time complexity of the following strcat function? void strcat(char* t; char* s) { while (*t) t++; while (*t++ = *s++); } Now, what is the time complexity of the following piece of code, which calls the above strcat function? void konkatenat0r(int n) { int i = 0; char* sentence = "The quick brown fox jumps over the lazy dog."; char* s = (char*) malloc(sizeof(s) * sizeof(sentence) * n); while (i < n) strcat(s, "The quick brown fox jumps over the lazy dog."); free((void*) s); }
oops replace char* sentence in line 2 of konkatenat0r with char sentence[]; yet another difference between char* s and char s[] :-)
u should use comments for making it easy for programmers
what was the result ????
comments? the strcat up there should be obvious to any C programmer, since it's essentially just composed of C idioms. The rest is self documenting.
but your code may read not a C programmer :D
oh and add a line right before the while loop, *s = '\0';
Join our real-time social learning platform and learn together with your friends!