Strings in C Part – 3

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for copy and concat string 
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str1[50],str2[50];
    int i;
    system("cls");
    printf("Enter a string: ");
    gets(str1); 
    // using inbuild
    // strcpy(str2,str1);
    // puts(str2);

    // // Without using inbuild
    //        i=0;
    //        while(str1[i]!='\0')
    //        {
    //             str2[i]=str1[i];
    //             i++;
    //        }
    //     str2[i]='\0';
    //     puts(str2);
    return 0;
}

Program 2

// Program for concat a string
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str1[50],str2[50],str3[100];
    int i;
    system("cls");
    printf("Enter First string: ");
    gets(str1); 
    printf("Enter Second string: ");
    gets(str2);
     //strcat(str1,str2);
     strcpy(str3,str1);
     strcat(str3,str2);
     
     puts(str3);
    
    return 0;
}

Program 3

// Program for concat a string
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str1[50],str2[50],str3[100];
    int i;
    system("cls");
    printf("Enter First string: ");
    gets(str1); 
    printf("Enter Second string: ");
    gets(str2);
    
    i=strcmpi(str1,str2);
    if(i==0)
      printf("String are same");
    else
       printf("String are not same"); 
    return 0;
}

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *