Programming / Computing

Compares two string

This program imitates how to compare two strings manually without using a C built-in library function ...............................................................................................................................................................................

 

 

 

 

#include<stdio.h>

#include<conio.h>

#include<string.h>

void xstrcmp();

void main()

{

xstrcmp();

}

 

void xstrcmp()

{

char a[20]= "vishaldeep singh",b[20];

gets(b);

int l1,l2,flag,i;

 

l1 = strlen(a);

l2 = strlen(b);

 

if(l1 != l2)

printf("the strings are not same");

else

{

flag = 0;

for(i=0;i<l1;i++)

{

if(a[i] != b[i])

{

printf("the strings are not same");

flag = 1;

break;

}

}

if(flag == 0)

printf("the strings are same");

}

}

 

© 2010 All rights reserved.

Make a free websiteWebnode