answersLogoWhite

0


Best Answer

#include

main()

{

//please read two strings int str1 and str2//

while(str1[i]!='/0' &&str2[i]!='/0')

if(str1[i]!=str2[i])

flag=1;

if(flag==1)

printf("equal");

} #include

main()

{

//please read two strings int str1 and str2//

while(str1[i]!='/0' &&str2[i]!='/0')

if(str1[i]!=str2[i])

flag=1;

if(flag==1)

printf("equal");

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to compare two strings with out using strcmp function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about General History
Related questions

'c' code to compare two strings using strcmp function?

char one [] = "A string" ;char two [] = "Different String" ;if (strcmp (one, two) == 0){puts ("The two strings are identical") ;}else{puts ("The two strings are different") ;}


What is the use of strcmp function in c plus plus?

strcmp is used to compare two strings. If the return value is zero, the two strings are the same. If the return value is less than 0, then the first string is less than the second string, otherwise the first string is greater than the second string. Strings are compared lexicographically, character by character.


Can you tell me a C program to find if the strings are equal using pointers?

It is called strcmp, part of the standard run-time library. Returns 0 if the two strings are equals, non-zero otherwise.


Write a script that accepts two strings from the user and compare two strings in web technology?

how to compare two strings that take input from the user and compare it. For example: i give first string as "THE" and give second string as "HTE" then return "match" if i give first as"THE" nd second string as "EHI" then return "NOtMatch" witout using STRCMP ... please help me


What does strcmp do in P hp?

"strcmp" accepts two strings and compares them, returning a positive or negative number representing the difference between their first differing characters. for example: strcmp('abc', 'abc'); // returns 0 strcmp('abc', 'abd'); // returns -1 strcmp('abc', 'abb'); // returns 1 strcmp('abc', 'tnthdaou'); // returns -1


Check wheather the strings are equal?

int string_equal (char *p1,char *p2) { int status = 1; while ((*p1 *p2) && status==1) { if (*p1++ != *p2++) status = 0; } return status; }


C program for comparison of two words?

strcmp


Is it possible to use the bubble sort algorithm to sort strings?

Bubble sort will be able to sort the items lexicographically, if you first assign the strings a relative value. The way strcmp in the C library does this is by returning the difference of the first different characters between the strings. For instance, if you call strcmp("Hello", "Highway"), strcmp will return 'e'-'i'. The ascii value of e on a unix system is 101 and the ascii value of i is 105, so it is returning the value 101-105 = -4 which will tell you that "Hello" is lexicographically smaller than "Highway". Doing this, you should be able to use any algorithm you want to sort the strings.


Write a c program to accept alist of 10 namews input by user then display the sorted list of names back to the user?

, since you seem to be needing help with your homework, I can give you some psuedo code to help you on your way! [CODE] DECLARE ARRAY names[10] FOR i = 0 TO 9 names[i] = READ INPUT FROM USER ENDFOR CALL FUNCTION sort WITH PARAMETERS names, 10 [/CODE] In the event that you have to create your own sorting function, I can give you some pseudo-code for the selection sort - a relatively easy-to-write sorting algorithm which doesn't involve any complicated data structures, or more advanced programming patterns, such as recursion. [CODE] FUNCTION sort WITH PARAMETER ARRAY names[], size FOR i = 0 TO size min = i FOR j = i + 1 TO size //Find the smallest unsorted element in the list IF names[min] > names[j] THEN min = j END FOR SWAP names[i] AND names[min] END FOR END FUNCTION [/CODE] The above function sorts in ascending order. The smallest element will be located at names[0], and the largest will be at names[size]. If you are allowed to, you may be able to use C's builtin strcmp() function to compare strings (found in #include <string.h>, or #include <cstring> for a C++ compiler). PLEASE REMEMBER that you can not compare strings directly in C!!! A C-string is nothing more than a memory address. If you attempt to compare two strings directly, then the compiler will NOT compare the strings, but the memory addresses where the strings are located! If you can't use strcmp(), you will have to write your own string comparing function. When reading input from the user, you will need to use scanf() for C. Also remember that C does not do any memory management for you, so you need to make sure you have enough space in your character arrays to read in a string from the user. Because you have multiple names, you will need to create an array of arrays. Something similar to this: "char names[NUMBER_OF_NAMES][CHARACTERS_IN_A_NAME];" where NUMBER_OF_NAMES = 10 and CHARACTERS_IN_A_NAME is an arbitrary number, large enough to store a name (I would pick something like 100).


Given str1 and str2 are two char arrays both of which are initialised to string hello then why does str1 equals equals str2 give result 0?

Comparison of str1 with str2 (str1 == str2) always returns false, because the addresses of the two strings are different - you are comparing addresses, not contents. (str1 and str2 are pointers) To compare the contents, use strcmp(str1, str2) or one of its equivalent library functions.Note:strcmp will return 0 as well, so use like this:if (strcmp (str1, str2)==0) puts ("They are equals");


How would you write a user defined function to compare two strings without using the library function?

/* ellipses, ..., used to emulate indentation */ int strcmp (const char* s1, const char* s2) { ... while (s1 != NULL && s2 != NULL) { /* scan both strings */ ... ... if (*s1 < *s2) return -1; /* first string less */ ... ... if (*s1 > *s2) return 1; /* first string greater */ ... ... s1++; ... ... s2++; ... } ... if (s1 == s2) return 0; /* strings equal or both empty */ ... if (s1 != NULL) return 1 else return -1; /* first string longer(1) / shorter(-1) */ } A slightly less computation-intensive version is: int strcmp(const char* s1, const char* s2) { ... if (s1==s2) ... ... return 0; ... while (*s1) ... ... if (*s1++^*s2++) ... ... ... if (--s1<--s2) ... ... ... ... return -1; ... ... ... else ... ... ... ... return 1; ... return 0; }


Write a program in 'c' language that accepts 10 strings as input and prints them in lexicographic order?

#include <stdio.h> #include <string.h> void main() { char a[4][25],temp[25]; int i,j; clrscr(); printf("Enter the names\n"); for (i=0;i<4;i++) gets(a[i]); for (i=0;i<3;i++) for (j=i+1;j<4;j++) { if (strcmp(a[i],a[j])>0) { strcpy(temp,a[i]); strcpy(a[i],a[j]); strcpy(a[j],temp); } } printf("Sorted strings are \n"); for (i=0;i<4;i++) puts (a[i]); getch(); }