answersLogoWhite

0


Best Answer

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

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you tell me a C program to find if the strings are equal using pointers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you swap two strings in c plus plus?

The most efficient way to swap strings is to point at them, and swap the pointers. Swapping the actual strings is problematic if the strings are of unequal length but impossible when they are also statically allocated. Dynamic strings can always be physically swapped, however it's highly inefficient. If it really must be done, then use a built-in method such as string::swap(). Otherwise just use string pointers and swap the pointers, never the strings themselves. The following example shows how both techniques can be used on statically allocated strings. Example output is show below. #include <iostream> using namespace std; void SwapPointers(char ** pp1, char ** pp2 ) { cout<<"\nSwapping pointers:"<<endl; char * t = *pp1; *pp1 = *pp2; *pp2 = t; } void SwapStatics(char * String1, char * String2, size_t len) { cout<<"\nSwapping static strings:"<<endl; while(len--) String1[len]^=String2[len]^=String1[len]^=String2[len]; } int main() { char s1[] = "one "; char s2[] = "two "; char s3[] = "three "; // Note that the output statements before and after // swapping are exactly the same, proving the strings // have really swapped. cout<<"Original strings:"<<endl; cout<<s1<<s2<<s3<<endl; SwapStatics(s1,s2,sizeof(s1)); cout<<s1<<s2<<s3<<endl; cout<<endl; // We cannot swap s3 with either s1 or s2, because // s1 and s2 don't have the space to accomodate s3. // However, we can use pointers instead: char * p1 = s1; char * p2 = s2; char * p3 = s3; // Again, note that the output statements are the // same before and after swapping, proving the // pointers have swapped. cout<<"Original pointers:"<<endl; cout<<p1<<p2<<p3<<endl; SwapPointers(&p1,&p3); cout<<p1<<p2<<p3<<endl; cout<<endl; // Just to prove the strings didn't swap... cout<<"The strings have not swapped:"<<endl; cout<<s1<<s2<<s3<<endl; cout<<endl; return(0); } Output: Original strings: one two three Swapping static strings: two one three Original pointers: two one three Swapping pointers: three one two The strings have not swapped: two one three


Program in c using pointers to interchange 2 values without using third variable?

swap (int *pa, int *pb) { *pa ^= *pb; *pa ^= *pa; *pa ^= *pb; }


What are the applications of pointers in using c language?

Accessing data by address. Some data-structures, like lists and trees, are usually implemented using pointers.


How do you print my name in c program in vertical manner using arrays?

you need strings to print any character(your name) this is not possible useing array:D


What is the Program for compare two strings using OR operator in java?

The String class includes two helpful methods: equals and compareTo.string1.equals(string2) will return true if the two strings contain the exact same charactersstring1.compareTo(string2) will return an int which describes the lexicographic relationship between the two strings. It will return a negative value if string1 is "less than" string2, a positive value if string1 is "greater than" string2, or zero if the two are equivalent strings.

Related questions

Write a c program to copy two strings using pointers?

nahi malum


How do you write a C program to copy to strings using pointers?

mystrcpy (char* dest, char* src) { while ((*dest++ = *src++) != '\0); }


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Is it possibly to return an array of strings in a function without using pointers in C plus plus?

No.


What will be the program to arrange numbers stored in array in ascending order using pointers?

sorry


How can you do the same thing as the program below but using strings and arrays in C language?

Program below?!


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


How do you run graphics program in C?

pro c language to implement linear search using pointers


What is the program for compare two strings using conditional operator in java?

System.out.println(a.equals(b) ? "They are equal" : "They are different");System.out.println(a.equals(b) ? "They are equal" : "They are different");System.out.println(a.equals(b) ? "They are equal" : "They are different");System.out.println(a.equals(b) ? "They are equal" : "They are different");


How do you swap two strings in c plus plus?

The most efficient way to swap strings is to point at them, and swap the pointers. Swapping the actual strings is problematic if the strings are of unequal length but impossible when they are also statically allocated. Dynamic strings can always be physically swapped, however it's highly inefficient. If it really must be done, then use a built-in method such as string::swap(). Otherwise just use string pointers and swap the pointers, never the strings themselves. The following example shows how both techniques can be used on statically allocated strings. Example output is show below. #include <iostream> using namespace std; void SwapPointers(char ** pp1, char ** pp2 ) { cout<<"\nSwapping pointers:"<<endl; char * t = *pp1; *pp1 = *pp2; *pp2 = t; } void SwapStatics(char * String1, char * String2, size_t len) { cout<<"\nSwapping static strings:"<<endl; while(len--) String1[len]^=String2[len]^=String1[len]^=String2[len]; } int main() { char s1[] = "one "; char s2[] = "two "; char s3[] = "three "; // Note that the output statements before and after // swapping are exactly the same, proving the strings // have really swapped. cout<<"Original strings:"<<endl; cout<<s1<<s2<<s3<<endl; SwapStatics(s1,s2,sizeof(s1)); cout<<s1<<s2<<s3<<endl; cout<<endl; // We cannot swap s3 with either s1 or s2, because // s1 and s2 don't have the space to accomodate s3. // However, we can use pointers instead: char * p1 = s1; char * p2 = s2; char * p3 = s3; // Again, note that the output statements are the // same before and after swapping, proving the // pointers have swapped. cout<<"Original pointers:"<<endl; cout<<p1<<p2<<p3<<endl; SwapPointers(&p1,&p3); cout<<p1<<p2<<p3<<endl; cout<<endl; // Just to prove the strings didn't swap... cout<<"The strings have not swapped:"<<endl; cout<<s1<<s2<<s3<<endl; cout<<endl; return(0); } Output: Original strings: one two three Swapping static strings: two one three Original pointers: two one three Swapping pointers: three one two The strings have not swapped: two one three


What are the advantages of using pointers in a program?

pointers points to the memory address of another variable.....in functions we have two kind of variables the actual and dummy variable. when we operate on variables..the value of dummy variables are effected, but if we want to make changes in the actual variable then we have to refer to their address..and we can reach to address of the variables by only using pointers.


Write a program to compare two strings with out using strcmp function?

#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"); }