Write a program to compare two strings which are given as command line argument.
#include<stdio.h> #include<stdlib.h> int main(int argc,char**argv) { int i,j; if(argc != 3) { printf("Enter two strings to compare\n"); return 0; } for(i = 0;argv[1][i];i++) { if(argv[1][i] != argv[2][i]) break; } if(argv[1][i] == '\0') printf("Same strings\n"); else printf("Different strings\n"); return 0; }
Output
./a.out Apple Apple Same strings
./a.out Apple BlackBerry Different strings