Tuesday, November 6, 2007

String Checking

Program : String Checking



#include<stdio.h>

#include<conio.h>


void main()

{

int i,y,x,l;

char a[20]; //the input string is stored in this character array

clrscr();

printf("String to be checked\n");

gets(a); //get the input string

l=strlen(a); //calculate the length of the string



if(a[l-3]=='a'&&a[l-2]=='b'&&a[l-1]=='c')

x=1;



else

x=0;



for(i=1;i<=l-3;i++)

{

if(a[i]=='a'||a[i]=='b')

y=1;

else

break;

}



if((x==1)&&(y==1))

printf("String accepted"); //output statement



else

printf("String not accepted\n");

getch();

}


0 comments: