Questions tagged [strcmp]

strcmp is a string compare function that is available in languages such as C, C++, PHP, Python and MATLAB.

strcmp is a string compare function that is available in languages such as C, C++, PHP, Python and MATLAB.

Structure

PHP
int strcmp ( string $str1 , string $str2 )
C
int strcmp( const char *lhs, const char *rhs );

Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Examples

PHP
echo strcmp("a","z"); // returns a negative number
echo strcmp("a","a"); // returns 0
echo strcmp("z","a"); // returns a positive number
C
int res = strcmp("a", "z"); // result is a negative number
int res = strcmp("a", "a"); // result is 0
int res = strcmp("z", "a"); // result is a positive number

References

https://en.cppreference.com/w/cpp/string/byte/strcmp

949 questions
-2
votes
1 answer

Why does using strcmp in this situation crash my program?

I'm having difficulties using strcmp. I make a call in a separate else statement (not listed), and it works fine. Is this a possible memory issue? while(inHere == 1) { int numberOfOccupiedTables = 0; cout << "\nSelect a table…
-2
votes
2 answers

PHP String Comparision

I am using below PHP function in Behat Mink to check the Email column values are in ascending or descending order.But the problem is its always fails.I just want to check if the subject or From of Email column in all rows are in ascending and…
Oasis
  • 480
  • 3
  • 16
-2
votes
1 answer

C : Comparing 2 Strings

I have to compare 2 strings, one from a file, and one from a user input, here is the file: Password abcdefg Star_wars jedi Weapon Planet long nail car fast cover machine My_little Alone Love Ghast The code for getting the string from the…
user3227362
  • 69
  • 1
  • 2
  • 8
-2
votes
2 answers

Mad on strcmp and strcpy

I am having trouble with this program. I'm not so familiar with the functions strcpy and strcmp. Can any professionals help me or give me some advice?
-2
votes
2 answers

PHP string comparison, === or strcmp not working

I have a hash map which contains certain keys which are the sorted versions of their values. For example, $hash = array( "abc" => "cab", "aas" => "sas" ); I also have an array of sorted strings($sorted_words) and I want to…
Mayank Kumar
  • 59
  • 1
  • 7
-2
votes
1 answer

C Programming. Comparing an array's contents.

I have an array as result of my program's input: //1. int i, numberOfOccurances; for(i = 0; i < numOfOccurrances; i++) { printf("%d",PrintOccurrances[i]); } and as an example output: 121 Now I want to compare this array so that I can…
-2
votes
2 answers

strcmp failing to compare strings properly

I'm having trouble using strcmp in C. I'm trying to compare a program's arguments using strcmp but even though the strings are the same it doesn't work. Here is the portion of code. while(strcmp(argv[i], "-e") != 0) So for i = 11 if I print the…
Atirag
  • 1,660
  • 7
  • 32
  • 60
-2
votes
1 answer

Segmentation Error in strcmp() function

The following code is to sort a linked list after creating it. The sorting algorithm used is Bubble Sort. Somehow the code raises a Segmentation Fault in the strcmp() function. PS: I also wrote another version where instead of counting the number of…
-3
votes
1 answer

How should I fix this error in strcmp function?

I wrote a code to sort employee details in ascending order of employee names. I'm seeing an error in the strcmp function where it says "strcmp makes pointer from integer without a cast". I'm having trouble solving this, can someone please help me…
-3
votes
1 answer

passing argument 1 of 'strcmp' makes pointer from integer without a cast C

I'm trying to compare a 2D array with a char but it keeps sending me this error and pointing at the array. if ((strcmp(matrixarray[j+k][i], "X"))==0 || (strcmp(matrixarray[j+k][i], currentword))==0) Minimal reproducible example: char…
Daina
  • 19
  • 4
-3
votes
1 answer

scanf(" %[^\n]", s); then how to strcmp in C?

scanf(" %[^\n]", in); then for example , i input Knock Knock and hit enter but my code block inside if (strcmp ("Knock Knock",out)==0) does not work please instruct me ,thanks a lot! char in[80],out[80]; void input(){ printf("Client: "); …
jenifer
  • 21
  • 1
  • 1
  • 4
-3
votes
1 answer

error: no matching function for call to 'strcmp' (Trying to set display userinfo function)

I am trying to create a function that displays details of user after they have signed up. Keep getting error about strcmp function. Note i'm getting from compiler: candidate function not viable: no known conversion from…
Dame
  • 1
  • 3
-3
votes
1 answer

How to create a pointer to only the first letter of a string

I'm trying to use strcmp() to compare to the first letter of the string line (which should be "V") with the letter "V" in c. I've tried several different methods of trying to create a pointer to only the first letter of the string in order to use…
Jakegar
  • 11
  • 2
-3
votes
1 answer

Compare string error in C language by using File IO and 2Darray

My programme is used for delete record in data file. I will ask the user input the "record number" that he want to delete.However, when i using strcmp this function to compare two string, it doesn't work. Problem:cannot using strcmp delete certain…
Hang Wui
  • 27
  • 5