String Comparison in C
Level 3121 keystrokes
Uses strcmp to compare two strings for equality.
C code
// Two separate arrays with the same text1char s1[] = "apple";2char s2[] = "apple";// s1 == s2 would compare addresses; strcmp compares the characters and returns 0 when they are equal3if (strcmp(s1, s2) == 0) { // Both contain "apple", so this line runs4 printf("Equal\n");5} else { // A nonzero result (negative or positive) means the strings differ6 printf("Not equal\n");7}Output
Equal
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
"× 8;× 4(× 4)× 4=× 4[× 2]× 2{× 2}× 2\× 2