Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

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); }

OpenStudy (anonymous):

oops replace char* sentence in line 2 of konkatenat0r with char sentence[]; yet another difference between char* s and char s[] :-)

OpenStudy (anonymous):

u should use comments for making it easy for programmers

OpenStudy (anonymous):

what was the result ????

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

but your code may read not a C programmer :D

OpenStudy (anonymous):

oh and add a line right before the while loop, *s = '\0';

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!