October 2009
M T W T F S S
    Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Categories

  • [+]ASP.NET (7) 
  • [+]C# (87) 
  • [—]C++ (13) 
  • [+]Delphi (20) 
  • [+]JavaScript (24) 
  • [+]Regular Expressions (7) 
  • [+]SQL (13) 
  • [+]VB (100) 
  • [+]VB.NET (4) 

Online

Users: 6 Guests
  • Loading...


    Loading...

    Login






    Register | Lost password?

    Register





    A password will be mailed to you.
    Log in | Lost password?

    Retrieve password





    A confirmation mail will be sent to your e-mail address.
    Log in | Register
  • String Recognition

    	/* String Recognition */
    
    	#include<stdio.h>
    	#include<conio.h>
    	#include<string.h>
    	#define SIZE_OF_STACK 50
    
    	char alphabet[50]="";
    	char input_string[50]="";
    	int no_of_alphabets=0,i;
    
    	struct stack
    	{
    		char slot[SIZE_OF_STACK];
    		int TOP;
    	};
    
    	int push(st,item)
    	struct stack *st;
    	char item;
    	{
    		if(st->TOP==SIZE_OF_STACK-1)
    		{
    			return 0; /* Push Operation Unsuccessful (Stack Overflow) */
    		}
    		else
    		{
    			st->TOP++;
    			st->slot[st->TOP]=item;
    			return 1; /* Push Operation Successful */
    		}
    	}
    
    	char pop(st)
    	struct stack *st;
    	{
    		if(st->TOP==-1)
    		{
    			return -1; /* Stack Underflow */
    		}
    		else
    		{
    			(st->TOP)--;
    			return st->slot[st->TOP+1];
    		}
    	}
    
    	int check_alphabet(c)
    	char c;
    	{
    		int temp;
    		for(temp=0;temp<=i;temp++)
    		{
    			if(c==alphabet[temp])
    			{
    				return 0; /* Character Repeated */
    			}
    		}
    
    		return 1; /* Character Okay */
    	}
    
    	char next_char(string)
    	char string[50];
    	{
    		static int count=0;
    		count++;
    		return string[count-1];
    	}
    
    	main()
    	{
    	 char temp,next;
    	 struct stack s;
    	 int x;
    	 s.TOP=-1;
    	 clrscr();
    	 printf("\nHow many alphabets does the language have ? : ");
    	 scanf("%d",&no_of_alphabets);
    
    	 for(i=0;i<no_of_alphabets;i++)
    	 {
    		printf("\nAlphabet %d : ",i+1);
    		temp=getche();
    		if(check_alphabet(temp)==1)
    		{
    			alphabet[i]=temp;
    		}
    		else
    		{
    			printf("	ERROR : Character already exists !");
    			i--;
    		}
    	 }
    	 alphabet[i]='\0';
    	 printf("\n\nEnter Input String : ");
    	 scanf("%s",input_string);
    
    	 push(&s,alphabet[i-1]);
    	 next=next_char(input_string);
    	 while(next!=alphabet[i-1])
    	 {
    		if(next=='\0')
    		{
    			printf("\nInvalid String !");
    			goto exit;
    		}
    		else
    		{
    			push(&s,next);
    		}
    		next=next_char(input_string);
    	 }
    
    	 while(s.slot[s.TOP]!=alphabet[i-1])
    	 {
    		next=next_char(input_string);
    		temp=pop(&s);
    		if(next!=temp)
    		{
    			printf("\nInvalid String !");
    			goto exit;
    		}
    	 }
    	 next=next_char(input_string);
    
    	 if(next=='\0')
    	 {
    		printf("\nValid String !");
    	 }
    	 else
    	 {
    		printf("\nInvalid String !");
    	 }
    	exit:
    	getch();
    	}
    
    Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • Digg
    • del.icio.us
    • Bloglines
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Technorati
    • TwitThis
    • Webnews

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

    Spam Protection by WP-SpamFree Plugin