program for comparing 2 strings without strcmp()
Answers were Sorted based on User's Feedback
Answer / ankitecian
int StrCmp(const char *_input1, const char *_input2)
{
int _cntr1 = 0;
int _flg = 0;
while(*(_input1 + _cntr1) != NULL || *(_input2 + _cntr1) !
= NULL)
{
if(*(_input1 + _cntr1) != *(_input2 + _cntr1))
{
_flg = -1;
}
_cntr1++;
}
return _flg;
}
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / ruchi
#include<stdio.h>
#include<conio.h>
int main()
{
char a[20],b[20];
int l1,l2,i=0,j=0;
printf("\nEntert the first string ");
while((a[i++]=getchar())!='\n');
l1=i-1;
printf("\nEnter the second string ");
while((b[j++]=getchar())!='\n');
l2=j-1;
if(l1>l2)
{
printf("\nThe first string is greater than the
second ");
}
else if(l2>l1)
{
printf("\n Second string is greater than the first ");
}
else
{
printf("\nBoth the strings are equal ");
}
getch();
}
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / bin
Here is a subroutine that does strcpy, returns 0 if both are equal, returns a positive number, if arg1 is higher else returns a negative number
int mystrcmp(char *s1, char *s2)
{
while (*s1 != 0 && *s2 != 0 && *s1 == *s2) {
++s1; ++s2;
}
return (*s1) - (*s2);
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / karthikeyan n p
#include<stdio.h>
#include<conio.h>
void main()
{
char st1[10],st2[10];
int i,sl1=0,sl2;
clrscr();
printf("\nEnter String1:");
scanf("%s",st1);
printf("\nEnter String2:");
scanf("%s",st2);
for(i=0;st1[i]!='\0';i++)
sl1=sl1+1;
for(i=0;st2[i]='\0';i++)
sl2=sl2+1;
if(sl1!=sl2)
{
printf("\nString is not equal.");
}
else
{
for(i=0;st1[i]!='\0' || st2[i]!='\0';i++)
{
if(st1[i]!=st2[i])
{ f=1; }
}
if(f==1)
printf("\nString is not equal.");
else
printf("\nString is equal.");
}
getch();
}
Is This Answer Correct ? | 1 Yes | 5 No |
What is pointer to pointer in c with example?
code for replace tabs with equivalent number of blanks
What is null character in c?
program for following output using for loop? 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
What is array within structure?
Write a c program to demonstrate Type casting in c?
how to make program without <> in libray.
Explain the difference between malloc() and calloc() in c?
The code is::::: if(condition) Printf("Hello"); Else Printf("World"); What will be the condition in if in such a way that both Hello and world are printed in a single attempt?????? Single Attempt in the sense... It must first print "Hello" and it Must go to else part and print "World"..... No loops, Recursion are allowed........................
14 Answers HOV Services, IBM, Potty,
Badboy is defined who has ALL the following properties: Does not have a girlfriend and is not married. He is not more than 23 years old. The middle name should be "Singh" The last name should have more than 4 characters. The character 'a' should appear in the last name at least two times. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers
How do I determine whether a character is numeric, alphabetic, and so on?
Can u return two values using return keyword? If yes, how? If no, why?