๐ŸŒ
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.
๐ŸŒ
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; } ... Your builder path starts here. Builders don't just know how to code, they create solutions that matter.
People also ask

How can strcmp() be used for string validation in C?
strcmp() is useful in validating user inputs. For example, you can compare user input with expected strings to check if the input matches the required value, ensuring correct input.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ strcmp in c
strcmp in C | String Comparison Function with Examples
What is the difference between strcmp() and == when comparing strings in C?
The strcmp in C programming function compares string content character by character, while == compares memory addresses, leading to incorrect results for string comparison.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ strcmp in c
strcmp in C | String Comparison Function with Examples
Can I compare strings of different data types using strcmp()?
No, strcmp() is specifically designed to compare strings (character arrays). If you need to compare different data types, you should convert them to strings before using strcmp in C programming.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ strcmp in c
strcmp in C | String Comparison Function with Examples
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ c_standard_library โ€บ c standard library strcmp function
C Standard Library strcmp Function
August 29, 2012 - Following is the syntax of the C library strcmp() function โˆ’ ... Zero, if the string are equal. Negative, if the first string is less than second string lexicographically. Positive, if the first string is greater than second string lexicographically. In this example, we demonstrate the usage of string characters comparison using strcmp() function.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ ref_string_strcmp.php
C string strcmp() Function
At the first mismatch, if the ASCII value of the character in the second string is greater then the function returns a negative number. The strcmp() function is defined in the <string.h> header file. ... If you want to use W3Schools services as an educational institution, team or enterprise, ...
๐ŸŒ
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 - Keep in mind that, after converting both strings to lowercase, the value of str1 is "apple", which is the same as the value of str2 in the ASCII. Therefore, when the strcmp() function is called, it returns 0, which indicates that the strings are equal. This can be useful when we want to compare strings that may differ in case but should be considered equal.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ c strcmp()
C strcmp() - Scaler Topics
April 17, 2024 - The strcmp function, a fundamental ... in C takes two character arrays as parameters and returns an integer value, which signifies whether the strings are equal, or if one is greater or less than the other. ... The strcmp function in C takes two parameters: string1 and string2, which are pointers to the character arrays that need to be compared...
๐ŸŒ
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 ...
๐ŸŒ
TechOnTheNet
techonthenet.com โ€บ c_language โ€บ standard_library_functions โ€บ string_h โ€บ strcmp.php
C Language: strcmp function (String Compare)
/* Example using strcmp by TechOnTheNet.com */ #include <stdio.h> #include <string.h> int main(int argc, const char * argv[]) { /* Create a place to store our results */ int result; /* Create two arrays to hold our data */ char example1[50]; char example2[50]; /* Copy two strings into our data arrays */ strcpy(example1, "C programming at TechOnTheNet.com"); strcpy(example2, "C programming is fun"); /* Compare the two strings provided */ result = strcmp(example1, example2); /* If the two strings are the same say so */ if (result == 0) printf("Strings are the same\n"); /* If the first string is less than the second say so (This is because the 'a' in the word 'at' is less than the 'i' in the word 'is' */ if (result < 0) printf("Second string is less than the first\n"); return 0; }
Find elsewhere
๐ŸŒ
Cppreference
en.cppreference.com โ€บ w โ€บ c โ€บ string โ€บ byte โ€บ strcmp
strcmp - cppreference.com
The behavior is undefined if lhs or rhs are not pointers to null-terminated byte strings. Negative value if lhs appears before rhs in lexicographical order. Zero if lhs and rhs compare equal. Positive value if lhs appears after rhs in lexicographical order. This function is not locale-sensitive, unlike strcoll and strxfrm. Run this code ยท #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 ?
๐ŸŒ
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, ... example of using strcmp() for string validation would be comparing a user's password input against a stored password....
๐ŸŒ
Wikibooks
en.wikibooks.org โ€บ wiki โ€บ C_Programming โ€บ string.h โ€บ strcmp
C Programming/string.h/strcmp - Wikibooks, open books for an open world
To compare a subset of both strings with case-insensitivity, various systems may provide strncasecmp, strnicmp or strncmpi. ... #include <stdio.h> #include <stdlib.h> #include <string.h> int main (int argc, char **argv) { int v; if (argc < 3) { fprintf (stderr, "Compares two strings\nUsage: %s string1 string2\n",argv[0]); return EXIT_FAILURE; } v = strcmp (argv[1], argv[2]); if (v < 0) printf ("'%s' is less than '%s'.\n", argv[1], argv[2]); else if (v == 0) printf ("'%s' equals '%s'.\n", argv[1], argv[2]); else if (v > 0) printf ("'%s' is greater than '%s'.\n", argv[1], argv[2]); return 0; }
๐ŸŒ
Cplusplus
cplusplus.com โ€บ reference โ€บ cstring โ€บ strcmp
strcmp - cstring
int strcmp ( const char * str1, const char * str2 ); Compare two strings ยท 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 ...
๐ŸŒ
The Open Group
pubs.opengroup.org โ€บ onlinepubs โ€บ 009604499 โ€บ functions โ€บ strcmp.html
strcmp
The strcmp() function shall compare the string pointed to by s1 to the string pointed to by s2. The sign of a non-zero return value shall be determined by the sign of the difference between the values of the first pair of bytes (both interpreted as type unsigned char) that differ in the strings ...
๐ŸŒ
OverIQ
overiq.com โ€บ c-programming-101 โ€บ the-strcmp-function-in-c
The strcmp() Function in C - C Programming Tutorial - OverIQ.com
Comparison starts off by comparing the first character from str1 and str2 i.e 'j' from "jkl" and 'j' from "jkm", as they are equal, the next two characters are compared i.e 'k' from "jkl" and 'k' from "jkm", as they are also equal, again the next two characters are compared i.e 'l' from "jkl" and 'q' from "jkm", as ASCII value of 'q' (113) is greater than that of 'l' (108), Therefore str2 is greater than str1 and strcmp() will return 5 ( i.e 113-108 = 5 ). It is important to note that not all systems return difference of the ASCII value of characters, On some systems if str1 is greater than str2 then 1 is returned. On the other hand, if str1 is smaller than str2 then -1 is returned. It is more likely that you will encounter this behaviour on your system. ... The following program compares two strings entered by the user.
๐ŸŒ
Aticleworld
aticleworld.com โ€บ home โ€บ how to use and implement own strcmp in c
How to use and Implement own strcmp in C - Aticleworld
August 23, 2020 - The strcmp function compares the string pointed to by s1 to the string pointed to by s2. If two strings are the same then strcmp() returns 0, otherwise, it returns a non-zero value.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ c_standard_library โ€บ c standard library strcmp function
strcmp() in C/C++
August 29, 2012 - The C Library strcmp() function is used to compare two strings. It checks each character in the string one by one until it finds a difference or reaches the end of the one string.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ c-runtime-library โ€บ reference โ€บ strcmp-wcscmp-mbscmp
strcmp, wcscmp, _mbscmp, _mbscmp_l | Microsoft Learn
Access to this page requires authorization. You can try changing directories. ... Compare strings. ... _mbscmp and _mbscmp_l cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported in Universal Windows Platform apps. int strcmp( const char *string1, const char *string2 ); int wcscmp( const wchar_t *string1, const wchar_t *string2 ); int _mbscmp( const unsigned char *string1, const unsigned char *string2 ); int _mbscmp_l( const unsigned char *string1, const unsigned char *string2, _locale_t locale );
๐ŸŒ
Vultr
docs.vultr.com โ€บ clang โ€บ standard-library โ€บ string-h โ€บ strcmp
C string.h strcmp() - Compare Two Strings | Vultr Docs
September 27, 2024 - ... #include <string.h> #include ... will return a non-zero value, indicating the strings are not identical. Use strcmp() for sorting an array of strings....