Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » ScannerRSS Feeds

Scanner of valide variable name in c

Posted By: Ballard Schmidt     Category: C++ Programming     Views: 2780

Scanner of valide variable name in c.


Dfa table

3 4 5
state L d _
0 start id special
1 id id special special
2 special id special special

Code for Scanner of valide variable name in c in C++ Programming

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


int main()
{
    char stt[4][4] = { NULL, '3', '4', '5', 
                        '0', '1', NULL, '2',
                        '1', '1', '2', '2',
                        '2', '1', '2', '2'};
    char ch;
    char state = '0';
    char variable[20];

    cout<<"Input variable name in c : ";
    cin>> variable;

    for(int i=0; i<20 && variable[i] != NULL; i++)
    {
        if(isalpha(variable[i]))
        {
            ch = '3';
        }
        elseif(isdigit(variable[i]))
        {
            ch = '4';
        }
        elseif(variable[i] == '_')
        {
            ch = '5';
        }
        for(int j=1; stt[0][j] != ch; j++);
        for(int k=1; stt[k][0] != state; k++);

        state = stt[k][j];

        if(state == NULL)
        {
            printf("Invalide variable name!!!!!!!!!!!");
            getchar();
            exit(0);
        }
    }

    printf("%s","Valide variable name");
    getchar();
    return 0;
}
  
Share: 


Didn't find what you were looking for? Find more on Scanner of valide variable name in c Or get search suggestion and latest updates.

Ballard Schmidt
Ballard Schmidt author of Scanner of valide variable name in c is from Frankfurt, Germany.
 
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!