Because strcmp() will return a negative integer in this case.

So change this:

if (strcmp(one, two) == 1) {

to this:

if (strcmp(one, two) != 0) {

to take into account all the cases that the strings differ.

Notice that you could have spotted that yourself by either reading the ref or by printing what the functions returns, like this:

printf("%d\n", strcmp(one, two));
// prints -23
Answer from gsamaras on Stack Overflow
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 169955-if-strcmp-str1-str2.html
if(!strcmp(str1, str2)
Do I assume correctly that if str1 = str2, then if(!strcmp(str1, str2) means true? To put it even more plainly, if the strings are equal, then strcmp returns 0, and since !0 == 1, yes, !strcmp(str1, str2) evaluates to true. You already figured that out in your first post.
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ else if statement not working with strcmp
r/C_Programming on Reddit: Else if statement not working with strcmp
November 25, 2015 -

I have this little program

   printf("Welcome to the command line interpreter \n");
  printf("Enter your command: \n");
fgets(command,80,stdin);

if(strcmp(command,"load"))
	load();

else if(strcmp(command,"execute"))
	execute();
else
	printf("nothing happened\n");

printf("your command is:%s\n",command);

return 0;

}

I only get the comparison of the first if, the rest is ignore even the else and I have no idea why. If I type load I do get the first function to work, but if I put something else I still get the result of the first if.

๐ŸŒ
Cplusplus
cplusplus.com โ€บ forum โ€บ beginner โ€บ 64978
if(!strcmp..... - C++ Forum
My problem is that the subsequent statement only makes sense if it's being executed when str1 = str2. Help. ... No. 1 is TRUE, not false. ... Also strcmp() returns either 0 or an positive integer, depending on if str1 matches str2, or where the first inconstant character is.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ strcmp-in-c-how-to-compare-strings-in-c
strcmp in C โ€“ How to Compare Strings in C
April 27, 2023 - I stored the output of the strcmp() ... The if statement checks the value of result and prints out the corresponding message depending on whether the strings are equal, or which string is less or greater....
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
strcmp() & if() & else if() Help - Programming - Arduino Forum
January 24, 2020 - The gist is I was taking a char ... to grab user input]; String stringOne = myChar myChar; if (stringOne == "something") { if (stringTwo == "something") {.......
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 625026 โ€บ languages โ€บ strcmp-statement
strcmp and if statement (C / C++ forum at Coderanch)
Expected Output: strcmp(indira,ujwal): ... Got the answer! In the ifstatement, when the conditional expression evaluates to a nonzero value, the computer will jump to the statements controlled by the ifstatement and execute them right away....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ strcmp-in-c
strcmp() in C %%sep%% %%sitename%% - GeeksforGeeks
December 13, 2025 - The strcmp function in C is used to compare two strings, with syntax: int strcmp(const char *str1, const char *str2);, where str1 and str2 are the strings to compare. It returns 0 if the strings are equal, a negative value if str1 is less than ...
Find elsewhere
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2017 โ€บ 11 โ€บ c-strcmp-function
C strcmp() Function with example
#include <stdio.h> #include <string.h> int main () { char str1[20]; char str2[20]; int result; //Assigning the value to the string str1 strcpy(str1, "hello"); //Assigning the value to the string str2 strcpy(str2, "hEllo"); result = strcmp(str1, str2); if(result > 0) { printf("ASCII value of ...
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ library-function โ€บ string.h โ€บ strcmp
C strcmp() - C Standard Library
The strcmp() compares two strings character by character. If the strings are equal, the function returns 0. ... The strcmp() function is defined in the string.h header file.
๐ŸŒ
Weber State University
icarus.cs.weber.edu โ€บ ~dab โ€บ cs1410 โ€บ textbook โ€บ 8.Strings โ€บ strcmp.html
8.2.2.4. strcmp
The strcmp function returns one of three possible values to inform a calling program which C-string comes first or whether the two are equal (i.e., have the same order). #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstring> using namespace std; int main() { char* s1 = "HELLO ...
๐ŸŒ
Quora
quora.com โ€บ Can-we-use-string-in-if-statement-in-C-programming
Can we use string in 'if' statement in C programming? - Quora
Answer (1 of 4): Typically you have to use a function (from the library) like i.e. strlen() to do that but there is an exception because a string in C is nothing else than a pointer to (an array of) char. Imagine we have: char mystring1[11]=โ€0123456789โ€ณ; char mystring2[10]=โ€012345678โ€ณ; mystrin...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ c_standard_library โ€บ c standard library strcmp function
C Standard Library strcmp Function
August 29, 2012 - It checks each character in the string one by one until it finds a difference or reaches the end of the one string. Additionally, the strings comparison is based on ASCII values. Following is the syntax of the C library strcmp() function โˆ’ ...