The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
strcat() is one of the inbuilt string function in c programming which is used to combine two strings to form a single one. The full form of strcat() is string concatenation.
The following diagram clearly illustrate the working principle of strcat() inbuilt string function in C.
In the above diagram strcat() takes two parameters say str1 and str2. Here str2 will be completely appending to str1.
strcat (str1, str2);
#include <stdio.h> #include<string.h> int main() { char str1[30] = "How are ", str2[30] = "you"; strcat (str1, str2); printf("Str1 : %s ", str1); return 0; }
Str1 : How are you
In the above program, strcat() simply concatenate two strings i.e str2 with str1.
#include <stdio.h> #include<string.h> int main() { char str1[30] = "How are "; char str2[30] = "you"; int i, j; for(i=0; str1[i]!='\0';i++){ //making using of variable i } for (j=0;str2[j] !='\0';j++){ str1[i] = str2[j]; i++; } printf("%s", str1); return 0; }
Str1 : How are you
The above program looks verbose but yields same the result.
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019