Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Data File StructureRSS Feeds

Program that uses this DFA and validates whether an entered string is valid integer or not.

Posted By: Aimee Hughes     Category: C++ Programming     Views: 3560

Generate a DFA to validate an integer data of C Language. Write a C/C++ program that uses this DFA and validates whether an entered string is valid integer or not.

2
state d
0 start 1
1 d 1

Code for Program that uses this DFA and validates whether an entered string is valid integer or not. in C++ Programming

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <process.h>

int main()
{
    char state = '0';
    char ch = NULL;
    char token[20]={NULL};
    char stt[3][2]= {NULL, '2',
             '0', '1',
             '1', '1'};
    cout<<"Input integer value : ";
    cin>>token;

    for(int i=0; token[i] != NULL; i++)
    {
        if(isdigit(token[i]))
        {
            ch='2';
        }
        else
        {
            printf("Invalide value");
            getchar();
            exit(0);
        }
        for(int j=1; j<3 && ch != stt[0][j]; j++);
        for(int k=1; k<2 && state != stt[k][0]; k++);
        state=stt[k][j];

    }
    printf("Valide value");    
    getchar();
    return 0;
}
  
Share: 



Aimee Hughes
Aimee Hughes author of Program that uses this DFA and validates whether an entered string is valid integer or not. is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!