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
-1
votes
2 answers

strcmp return same value in c

So here I wrote this program which produces 2 sets of numbered words connected to them so later we can generate words from combining words from these sets (each set separately), every time we generate these two words it compares them if these words…
-1
votes
1 answer

The address of 'target_tweet' will never be NULL!?

How do I go about getting around this warning? it obviously prevents me from compiling with gcc. Am I missing something? #include #include int main(void) { int MAX_TWEET_SIZE = 32; char…
Joseph
  • 9
  • 2
-1
votes
2 answers

Comparing String in C and each element is a pointer to a string

For my code below, if i type number four and will, ed, bob, bill, i want the input to be ryan. basically the output to be whichever that is not one of the inputs among the names. And it should be the one and only name always. But I'm not getting…
-1
votes
1 answer

How to properly use strcmp in a function

I'm having a hard time understanding how to use strcmp. It seems like changes I make to the strings being sent to the equals() function don't affect the outcome of Tests 1a - 1d. What is the purpose of the exclamation points in front of the function…
Kaynum
  • 1
  • 1
-1
votes
3 answers

How does this basic reimplementation of strlen() find the length?

My professor showed us this sample implementation of a function to find the length of a string, saying that this is how you would do it without actually using the strlen() function: int length(char word) { int i; for (i = 0; word[i]!='\0';…
Bob Ross
  • 61
  • 7
-1
votes
5 answers

strcmpi integer without a cast error

I'm trying to create a program that removes vowels from a string, add them into a vector and then give the user the possibility of having the original code again. In my code i have this: char s[20]; And soon after i have this…
hfa2010
  • 3
  • 2
-1
votes
2 answers

Comparing passwords in php

I have this following if-case, but I can't get it to work properly. I have a database that stores md5 encrypted passwords as varchar. I let the user enter his/her password and username in a form and send it to php the normal way. $nickName =…
clockw0rk
  • 576
  • 5
  • 26
-1
votes
1 answer

My comparison of two strings for a hangman game doesn't work properly

I've been working on a hangman game for a class course and I'm almost done. However, I've stumbled upon a problem that I can't seem to fix. First, the computer choose a random word from a text file, takes the lenght of that word and with that length…
JonteG
  • 23
  • 4
-1
votes
3 answers

Avoiding segmentation fault

I'm trying to port a software to Linux. It works greatly on Windows. On Linux it gives me a segmentation fault on strcmp: int main(void) { ... char* comando; char istruzione[100]; scanf("%[^\n]%*c", istruzione); comando =…
Angelo Tricarico
  • 1,333
  • 1
  • 19
  • 36
-1
votes
1 answer

Excel VBA StrCmp sub or function not defined

I am trying to use the StrCmp function in excel vba (using excel 2007) and am getting the following error: Compile Error: Sub or Function Not Defined. Here is my code: StrCmp(Worksheets(1).Range("I" & x).Value, "Critical") Any help would be…
user1725940
  • 93
  • 4
  • 10
-1
votes
2 answers

C language, where is the segmentation fault?

here is the function where im getting the segmentation fault void searchcity() { struct city *ptr=citylist; printf("Which city would you like me to search?: "); scanf("%s",searchedcity); // printf("%s",searchedcity); while(ptr) …
Alex
  • 73
  • 1
  • 3
  • 13
-1
votes
1 answer

using strcmp with an array

Here is the full code. it keeps freezing now typedef struct { char *name; } NAME; setting the array to be null and then later on i expand it depending on how many entries i need to add. NAME *array = NULL; int itemCount = 0; // items…
user2267220
-1
votes
1 answer

Comparing contents received at Socket with a String in UDP

I have developed a UDP Client Server Application. Now I want to check if the client sends a string "EXIT", the Server receives this string, compares it with "EXIT" string and the program exits. But in my case, the Server is not able to compare the…
Ayse
  • 2,676
  • 10
  • 36
  • 61
-1
votes
2 answers

PHP for HTML forms

I have the below drop down list as part of a HTML form: Print Options: