How to implement the strcat function in C

1 Answer

0 votes
#include <stdio.h>

char* strcat(char* s1, const char* s2) {
	char* p;

	// point to end of s1
	for (p = s1; *p != '\0'; p++)
		;
	//  copy s2 to end of s1
	for (; (*p = *s2) != '\0'; p++, s2++)
		;
	return s1;
}

int main()
{
	char str1[64] = "c programming";
	char str2[32] = " language";

	strcat(str1, str2);

	puts(str1);

	return 0;
}




/*
run:
         
c programming language
      
*/

 



answered Dec 15, 2022 by avibootz
edited Dec 16, 2022 by avibootz

Related questions

1 answer 114 views
114 views asked Dec 7, 2022 by avibootz
1 answer 202 views
1 answer 191 views
1 answer 85 views
85 views asked Jun 10, 2025 by avibootz
1 answer 132 views
...