C Program to Compare the Two Strings

Write a program to compare two strings by passing them to a function. The function will return 1 if both the strings are the same, else it returns 0.
Buffer Overflow Attack Real-life Example, Buffer Overflow C, Buffer Overflow C Example, Buffer Overflow Code Injection Example, Buffer Overflow Command Line, Buffer Overflow Example, How To Avoid Buffer Overflow In C, How To Check Buffer Overflow In C
Buffer Overflow Attack Real-life Example, Buffer Overflow C, Buffer Overflow C Example, Buffer Overflow Code Injection Example, Buffer Overflow Command Line, Buffer Overflow Example, How To Avoid Buffer Overflow In C, How To Check Buffer Overflow In C

Write a program to compare two strings by passing them to a function. The function will return 1 if both the strings are the same, else it returns 0. 

#include<stdio.h>
int stringcompare(char*,char*);
int main()
{
charstr1[20]; // declaration of char array
charstr2[20]; // declaration of char array
printf(“Enter the first string : “);
scanf(“%s”,str1);
printf(“\nEnter the second string : “);
scanf(“%s”,str2);
intcompare=stringcompare(str1,str2); // calling stringcompare() function.
if(compare==0)
printf(“strings are equal”);
else
printf(“strings are not equal”);
return 0;
}
// Comparing both the strings using pointers
int stringcompare(char *a,char *b)
{
intflag=0;
while(*a!=’\0′ && *b!=’\0′) // while loop
{
if(*a!=*b)
{
flag=1;
}
a++;
b++;
}
if(flag==0)
return0;
else
return1;
}
Buffer Overflow Attack Real-life Example, Buffer Overflow C, Buffer Overflow C Example, Buffer Overflow Code Injection Example, Buffer Overflow Command Line, Buffer Overflow Example, How To Avoid Buffer Overflow In C, How To Check Buffer Overflow In C
Buffer Overflow Attack Real life Example Buffer Overflow C Buffer Overflow C Example Buffer Overflow Code Injection Example Buffer Overflow Command Line Buffer Overflow Example How To Avoid Buffer Overflow In C How To Check Buffer Overflow In C
Total
0
Shares
Leave a Reply

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

Prev
Guessing Games – Python Program
Buffer Overflow Attack Real-life Example, Buffer Overflow C, Buffer Overflow C Example, Buffer Overflow Code Injection Example, Buffer Overflow Command Line, Buffer Overflow Example, How To Avoid Buffer Overflow In C, How To Check Buffer Overflow In C

Guessing Games – Python Program

Guess A Number Between 1 And 100 Python Code

Next
9 Ways to Boost Your Style Confidence and Have More Fun

9 Ways to Boost Your Style Confidence and Have More Fun

Totally normal things to experience in your relationship right now

You May Also Like

You cannot copy content of this page