این برنامه که با زبان C نوشته شده،دو رشته را از ورودی دریافت و با هم مقایسه می کند. برای دیدن سورس برنامه به ادامه مطلب مراجعه فرمایید.
#include <stdio.h> #include <conio.h> first_dif(char *, char *, int); int main() { char st1[40], st2[40] ; int compcase = 1 ; clrscr(); printf(" enter first string:") ; gets(st1) ; printf(" enter second string:"); gets(st2) ; first_dif(st1, st2, compcase) ; getch(); return 0; } //******************** first_dif(char *s1, char *s2, int ignore_case) /* if ignore_case is 1 ,ignore case of letter */ { int i ; char a , b ; for(i = 0; *s1 && *s2; s1++, s2++, i++) if(*s1 != *s2) { if(ignore_case) { a = (*s1 >= 'a' && *s1 <= 'z') ? *s1 -= 32 : *s1; b = (*s2 >= 'a' && *s2 <= 'z') ? *s2 -= 32 : *s2; if(a != b) break ; }//end of if else break; }//end of if if(*s1 || *s2) { printf("\n strings are not equal,"); printf(" the first difference occurs in :%d", i + 1); } else printf("\n strings are equal .") ; }
|