Write the function ADD having as parameters STR1 and STR2 which copies the string STR2 to the end of the string STR1.
Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
void ADD(char STR1[], char STR2[])
{
int i = 0 , j=0;
while (STR1[i]) /* go to the end of STR1 */
i++;
while (STR2[j]) /* copy STR2 to the end of STR1 */
{
STR1[i] = STR2[j];
i++;
j++;
}
STR1[i] = '\0'; /* terminate STR1 */
}
void main()
{
char str1[100], str2[100];
printf("Enter a string: ");
gets(str1);
printf("Enter a string: ");
gets(str2);
ADD(str1,str2);
puts(str1);
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Sorting using quick-sort algorithm