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
How to store passwords securely with PBKDF2
hashing-salting-How-to-store-passwords-securely-PBKDF2

How to store passwords securely with PBKDF2

How to store passwords securely with PBKDF2

Next
Buffer Overflow – Stack overflow – C Programming Lab Project
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 – Stack overflow – C Programming Lab Project

Congratulations, you have mitigated the overflow!

You cannot copy content of this page