+ 1

Difference between strcmp() and strncmp().

Please explain in detail

29th Oct 2019, 2:33 PM
Aditya Gupta
Aditya Gupta - avatar
5 Answers
+ 8
With strncmp, you can specify the number of chars up to which you want to compare two strings.
30th Oct 2019, 1:18 AM
Sonic
Sonic - avatar
+ 7
Coding Wala You have everything explained in the tutorial. Please, read the COMMENTS in the lessons you can find a great examples and explanations. strcmp(str1, str2) - returns 0 when str1 is equal to str2; - less than 0 when str1 < str2; and - greater than 0 when str1 > str2. strncmp(str1, str2, n) - returns 0 when the first 'n' characters of str1 is equal to the first 'n' characters of str2; - less than 0 when str1 < str2; and - greater than 0 when str1 > str2. • https://www.sololearn.com/learn/C/2937/ • https://code.sololearn.com/cy0uzj5ehg0S/?ref=app
29th Oct 2019, 4:05 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 3
I can't be anymore detailed than these reference: In brief, the `strncmp` allows to set a limit of how many characters to be compared. http://www.cplusplus.com/reference/cstring/strcmp/ http://www.cplusplus.com/reference/cstring/strncmp/
29th Oct 2019, 3:35 PM
Ipang
+ 1
I also want to know the same
29th Oct 2019, 2:35 PM
Codx
Codx - avatar
+ 1
Thanks to everybody for providing the clarification
5th Nov 2019, 4:44 AM
Aditya Gupta
Aditya Gupta - avatar