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
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strcmp-in-c
strcmp() in C %%sep%% %%sitename%% - GeeksforGeeks
December 13, 2025 - Explanation: In this code, strcmp is used to compare two strings, s1 and s2. Since both strings are identical ("g f g"), strcmp returns 0, indicating the strings are equal. The program then prints "Equal".
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
🌐
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); printf("strcmp(str1, str3) = %d\n", result); return 0; }
🌐
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 a `while` loop to compare each character in both strings.
🌐
Scaler
scaler.com › home › topics › string comparison in c
String Comparison in C - Scaler Topics
January 11, 2024 - The strcmp() function compares both strings characters. If both strings have the same character at the same index till all of the characters have been compared or the pointer reaches the null character '\0' in both strings then we can say that ...
🌐
TechOnTheNet
techonthenet.com › c_language › standard_library_functions › string_h › strcmp.php
C Language: strcmp function (String Compare)
string.h · 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: int ...
🌐
Cppreference
en.cppreference.com › w › c › string › byte › strcmp
strcmp - cppreference.com
#include <stdio.h> #include <string.h> void demo(const char* lhs, const char* rhs) { const int rc = strcmp(lhs, rhs); const char* rel = rc < 0 ? "precedes" : rc > 0 ? "follows" : "equals"; printf("[%s] %s [%s]\n", lhs, rel, rhs); } int main(void) { const char* string = "Hello World!"; demo(string, "Hello!"); demo(string, "Hello"); demo(string, "Hello there"); demo("Hello, everybody!"
Find elsewhere
🌐
Cplusplus
cplusplus.com › reference › cstring › strcmp
Cplusplus
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. This function performs a binary comparison of the characters.
🌐
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() function in a new variable named result, like earlier. 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 ...
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › strcmp in c
strcmp in C | String Comparison Function with Examples
February 5, 2025 - The strcmp in C function is used to compare two strings character by character. It returns 0 if both strings are equal, a positive value if the first string is greater, and a negative value if it’s smaller.
🌐
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 ...
🌐
LabEx
labex.io › questions › how-to-compare-strings-in-c-136079
How to Compare Strings in C | LabEx
July 25, 2024 - Learn how to compare strings in C using strcmp function, characterbycharacter methods, and wildcard matching for effective programming.
🌐
GNU
gnu.org › software › libc › manual › html_node › String_002fArray-Comparison.html
String/Array Comparison (The GNU C Library)
The sign of the value indicates the relative ordering of the first part of the strings that are not equivalent: a negative value indicates that the first string is “less” than the second, while a positive value indicates that the first string is “greater”. The most common use of these functions is to check only for equality.
🌐
Reddit
reddit.com › r/learnprogramming › fast string comparisons in c
r/learnprogramming on Reddit: Fast String comparisons in C
October 29, 2023 -

Hi, I'm working just for fun on a fast comparison for strings written in C, with the intent of being faster than the normal strncmp function, which is currently the code bellow

```
int fast_strncmp(const char *str1, const char *str2, int len) {
    const char *final_pos = (str1 + len) - 4;
    while (str1 < final_pos) {
        // if characters differ, or end of the second string is reached
        if (*((uint32_t *)str1) != *((uint32_t *)str2)) {
            break;
        }
        // move to the block of characters
        str1 += 4;
        str2 += 4;
    }
    final_pos += 4;
    while (str1 < final_pos) {
        if (*str1 != *str2 || *str1 == 0 || *str2 == 0) {
            return *str1 - *str2;
        }
        // move to the next pair of characters
        str1++;
        str2++;
    }
    return 0;
}
```

Is there any clear problem with the code that could make it a bad option for fast string comparisons. When I wrote it a couple of weeks ago, I didn't think there could be any problem with it, but this week I was watching a couple of videos about C programming and it was mentioned that casting an array of 4 uint8_t to a uint32_t could be a problem. I'm even using this function at work and haven't had a single problem or warning, but since I'm planning to make a youtube video about it, I want to guarantee that my code won't be a problem for other people.

On top of that I've made a couple of benchmarks on the performance to be sure it really is fast, so I've compared it to strncmp and an implementation by https://github.com/mgronhol, that I found here: https://mgronhol.github.io/fast-strcmp/, which got me the following results:

EDIT: reddit was not cooperating with me posting the results text in a well formatted way, so here's the link to the file:

https://github.com/BenjamimKrug/fast_string_comparison/blob/main/results.txt

As you can see, running on the STM32 and the ESP32, my algorithm runs faster by a little compared to the fast_compare function by mgronhol, but running on my PC, it's performing terribly. Does anyone know why that is?

You can find more info about the code in my github repository where I put everything related to this test: https://github.com/BenjamimKrug/fast_string_comparison

P.S.: Sorry if this is the wrong subreddit for this kind of thing, I was going to post it on r/programming, but after reading the rules, I saw that maybe it was best to post it here.

EDIT: fixed code formatting

🌐
Vultr
docs.vultr.com › clang › standard-library › string-h › strcmp
C string.h strcmp() - Compare Two Strings | Vultr Docs
September 27, 2024 - The strcmp() function in C is a versatile and powerful tool for comparing two strings. Understanding the integer it returns enables the determination of not only the equality but also the lexical order of strings.
🌐
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 ...
🌐
Quora
quora.com › Can-we-compare-two-strings-using-in-C
Can we compare two strings using == in C? - Quora
Answer (1 of 4): Answer on applies only on C strings (char array), not c++ string :- The answer to your question is no, we cannot compare two strings using == in C because a string in C language is an array of characters and the name of the ...