You can't (usefully) compare strings using != or ==, you need to use strcmp:

while (strcmp(check,input) != 0)

The reason for this is because != and == will only compare the base addresses of those strings. Not the contents of the strings themselves.

Answer from Mysticial on Stack Overflow
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ library-function โ€บ string.h โ€บ strcmp
C strcmp() - C Standard Library
#include <stdio.h> #include <string.h> int main() { char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd"; int result; // comparing strings str1 and str2 result = strcmp(str1, str2); printf("strcmp(str1, str2) = %d\n", result); // comparing strings str1 and str3 result = strcmp(str1, str3); ...
People also ask

How do we compare a substring of a string in C?
To compare a substring in C, you can use `strncmp()`, which compares a specified number of characters from two strings. Another method involves manually iterating through the desired portion of the string and comparing it character by character. Ensure that the substring is of the same length for a valid comparison.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ string comparison in c
String Comparison in C: Methods & Examples
What is string comparison in C?
String comparison in C is the process of determining whether two strings are equal, or which one is lexicographically greater or smaller. C doesn't have a built-in string data type, so strings are typically arrays of characters. This makes string comparison crucial for tasks like sorting, searching, and validation in C programs.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ string comparison in c
String Comparison in C: Methods & Examples
Can we compare strings in C without `strcmp()`?
Yes, strings in C can be compared manually by iterating over each character of both strings. You can use a loop to check if each character is the same. If you find a mismatch or reach the end of a string, you can conclude the comparison, returning values similar to `strcmp()` results.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ string comparison in c
String Comparison in C: Methods & Examples
๐ŸŒ
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 - The strings are equal. Here I converted both strings into lowercase. I used a for loop to change all the characters in the string to lowercase using the function tolower().
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ string comparison in c
String Comparison in C - Scaler Topics
January 11, 2024 - If the function returns 0, then the strings are equal otherwise, strings are not equal. String comparison in C also possible by using pointers. In this approach, we use pointers to traverse the strings and then compare the characters pointed by the pointer. ... In the code example, Weโ€™ve declared two char arrays str1 ,str2 and then take input for them.
๐ŸŒ
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 ...
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ string comparison in c
String Comparison in C: Methods & Examples
May 5, 2025 - The strings are equal. ... We use two pointers, `str1` and `str2`, to traverse the strings character by character.
๐ŸŒ
Reddit
reddit.com โ€บ r/cpp_questions โ€บ simple comparison between std::string and c-string
r/cpp_questions on Reddit: simple comparison between std::string and c-string
August 26, 2023 -

Hello,

I am discussing with a person who believes that

std::string msg = "Hello";

if (msg == "Hello") { // UB?
   ...
}

According to the person, this line "if (msg == "Hello") {" is UB.

Have you seen this "operator==" as UB?

I have checked the C++ specification (from c++11), and it's acceptable. I checked the std::string implementation (GNU GCC 5 and the latest) and operator== calls std::string::compare and then "traits". Passing cstring in operator== is fine too...

Toolchain is ARM for 32bit architecture and std is c++11/14.

His arguments are based on Stackoverflow posts which are more than 10y ago...

Thank you

Find elsewhere
๐ŸŒ
Cplusplus
cplusplus.com โ€บ reference โ€บ cstring โ€บ strcmp
Cplusplus
Compares the C string str1 to the C string str2. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null-character is reached.
๐ŸŒ
TechOnTheNet
techonthenet.com โ€บ c_language โ€บ standard_library_functions โ€บ string_h โ€บ strcmp.php
C Language: strcmp function (String Compare)
In the C Programming Language, the strcmp function returns a negative, zero, or positive integer depending on whether the object pointed to by s1 is less than, equal to, or greater than the object pointed to by s2. The syntax for the strcmp function in the C Language is: ... An array to compare. ... An array to compare. The strcmp function returns an integer. The return values are as follows: In the C Language, the required header for the strcmp function is: ... /* Example using strcmp by TechOnTheNet.com */ #include <stdio.h> #include <string.h> int main(int argc, const char * argv[]) { /* Cr
๐ŸŒ
Quora
quora.com โ€บ How-do-I-check-if-two-strings-are-equal-in-C-1
How to check if two strings are equal in C - Quora
Answer (1 of 3): You can check whether two strings are equal or not by using strcmp() function. This is a built-in string function which is present in string.h header file. strcmp() function takes 2 strings as parameters and returns integer value as output based on the comparision. This may be z...
๐ŸŒ
LabEx
labex.io โ€บ questions โ€บ how-to-compare-strings-in-c-136079
How to Compare Strings in C | LabEx
July 25, 2024 - Here's an example of how to use strcmp(): #include <stdio.h> #include <string.h> int main() { char str1[] = "Hello"; char str2[] = "World"; char str3[] = "Hello"; if (strcmp(str1, str2) < 0) { printf("%s is lexicographically less than %s\n", str1, str2); } else if (strcmp(str1, str2) > 0) { printf("%s is lexicographically greater than %s\n", str1, str2); } else { printf("%s is equal to %s\n", str1, str2); } if (strcmp(str1, str3) == 0) { printf("%s is equal to %s\n", str1, str3); } else { printf("%s is not equal to %s\n", str1, str3); } return 0; } This code will output: Hello is lexicographically less than World Hello is equal to Hello ยท
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ ref_string_strcmp.php
C string strcmp() Function
C Examples C Real-Life Examples ... ยท Compare two strings to see which is greater: char myStr1[] = "ABCD"; char myStr2[] = "ABCE"; int cmp = strcmp(myStr1, myStr2); if (cmp > 0) { printf("%s is greater than %s\n", myStr1, ...
๐ŸŒ
W3Resource
w3resource.com โ€บ c-programming โ€บ string โ€บ c-strcmp.php
C strcmp() function
Original text: 1234567890 1234567890 Compare the said two strings: First is equal to second. Original text: 12345678901 12345678900 Compare the said two strings: First is greater than second. Original text: 12345678901100345678 12345678901297650033 First is less than second. ... This example demonstrates using strcmp() to check if the user's input matches a predefined password...
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ strcmp in c
strcmp in C | String Comparison Function with Examples
February 5, 2025 - It is done character by character, and the ยท function determines whether the strings are equal or which one is lexicographically greater or smaller. A real-world example of using strcmp() for string validation would be comparing a user's password input against a stored password.
๐ŸŒ
Cplusplus
cplusplus.com โ€บ reference โ€บ string โ€บ string โ€บ compare
std::string::compare
Compares the value of the string object (or a substring) to the sequence of characters specified by its arguments. The compared string is the value of the string object or -if the signature used has a pos and a len parameters- the substring that begins at its character in position pos and spans ...
๐ŸŒ
Vultr
docs.vultr.com โ€บ clang โ€บ standard-library โ€บ string-h โ€บ strcmp
C string.h strcmp() - Compare Two Strings | Vultr Docs
September 27, 2024 - In C programming, comparing two strings is a common task that can be performed using the strcmp() function from the string.h library. This function is essential for operations like sorting lexicographically or checking string equality, which are foundational in many algorithms and applications ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-compare-two-strings-in-C
How to compare two strings in C - Quora
Answer (1 of 5): The best way is to really learn the language. All of it. Not just the syntax and data types, but the tools which allow you to make full use of the various parts that collectively make it a proper programming language. For this particular question it would behoove you to read thr...
๐ŸŒ
Shiksha
shiksha.com โ€บ home โ€บ it & software โ€บ it & software articles โ€บ programming articles โ€บ compare strings with strcmp function in c
Compare Strings with strcmp() Function in C - Shiksha Online
December 21, 2023 - In this example, the strcmp function is used to compare a string str with an empty string โ€ โ€œ. If both strings are equal, the string is empty.
๐ŸŒ
Weber State University
icarus.cs.weber.edu โ€บ ~dab โ€บ cs1410 โ€บ textbook โ€บ 8.Strings โ€บ strcmp.html
8.2.2.4. strcmp
Equal strings. C++ doesn't have a function specifically designed for testing two C-strings for equality, so programs use the strcmp function. Notice the NOT operator, !, in the second highlighted example.