Write a program to concatenate two strings specific element in an array
without using library
functions.
Using for loop
- #include <stdio.h>
- int main()
- {
- char str1[100];
- char str2[100];
- int i, j;
- printf("please enter first string : ");
- scanf("%s", str1);
- printf("Please enter second string : ");
- scanf("%s", str2);
- for(i=0; str1[i] != '\0'; i++);
- for(j=0; str2[j] != '\0'; j++, i++) {
- str1[i] = str2[j];
- }
- str1[i] = '\0';
- printf("Concatenate is : %s", str1);
- return 0;
- }
Using while loop
- #include <stdio.h>
- int main()
- {
- char str1[100];
- char str2[100];
- int i=0, j=0;
- printf("please enter first string : ");
- scanf("%s", str1);
- printf("Please enter second string : ");
- scanf("%s", str2);
- while(str1[i] != '\0')
- i++;
- while(str2[j] != '\0'){
- str1[i] = str2[j];
- j++;
- i++;
- }
- str1[i] = '\0';
- printf("Concatenate is : %s", str1);
- return 0;
- }
একটি মন্তব্য পোস্ট করুন