iam serching job somany comapnies asking this question but iam not getting lz reply anybody
Write a program in c for strcmp without using library function?
******************************
returns
zero if both are equal
-1 if stringlength is not equal // u can configure any value
non-zero value when not equal ( max used to return the maximum of str1 and str2. u may choose char of str1 also)
i dont have compiler so i didnt tested.
Please check in for loop whether it should i%26lt;len1 or i%26lt;=len1
********************
int mystrcmp(char * str1, char * str2)
{
int i=0,len1=0,len2=0,flag=0;
while(str1[i++]!='\0')
len1++;
i=0;
while(str2[i++]!='\0')
len2++;
if(len1!=len2)
flag=-1;
for(i=0;i%26lt;len1 %26amp;%26amp; flag==0;i++)
{
if(str1[i]==str2[i])
continue;
flag=max(str1[i],str2[i]);
break;
}
return flag;
}
Reply:If you don't know how to do this without outside assistance, you shouldn't go to work for a company that expects you to be able to do so.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment