prev | Character Arrays - String manipulations: 96.grep command - whether given pattern/string exist or not(16.05.2010) /* Program# 96 date : 10-01-2009 Pattern matching --will work only if input given as i love this universe$universe$ In : i love this universe$ universe$ bug:because '\n' gets into b[0] */ #include <stdio.h> main(){ char a[100],b[100]; int i,j,k; i=0; scanf("%c",&a[i]); while(a[i]!='$'){ i++; scanf("%c",&a[i]); } a[i]='\0'; j=0; scanf("%c",&b[j]); while(b[j]!='$'){ j++; scanf("%c",&b[j]); } b[j]='\0'; i=0; while(a[i]!='\0'){ j=0; k=i; while((b[j]==a[k]) && (b[j]!='\0')){ j++; k++; } if(b[j]=='\0'){ printf("\nPattern exists"); return; }else i++; } printf("\n pattern not exists"); } |
next |