- Learn C By Examples Time
- Learn C by Examples - Home
- C Examples - Simple Programs
- C Examples - Loops/Iterations
- C Examples - Patterns
- C Examples - Arrays
- C Examples - Strings
- C Examples - Mathematics
- C Examples - Linked List
- C Programming Useful Resources
- Learn C By Examples - Quick Guide
- Learn C By Examples - Resources
- Learn C By Examples - Discussion
Program to Compare Strings in C
Implementation
Now, we shall see the actual implementation of the program −
#include <stdio.h> int main() { char s1[] = "advise"; char s2[] = "advice"; int n = 0; unsigned short flag = 1; while (s1[n] != '\0') { if(s1[n] != s2[n]) { flag = 0; break; } n++; } if(flag == 1) { printf("%s and %s are identical\n", s1, s2); } else { printf("%s and %s are NOT identical\n", s1, s2); } return 0; }
Output
Output of this program should be −
advise and advice are NOT identical
string_programs_in_c.htm
Advertisements