Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Miscellaneous ProblemsRSS Feeds

Comment line in c

Posted By: Rambert Fischer     Category: C++ Programming     Views: 1968

Comment line in c

Dfa table

7 8 9
State / * any
0 start 1 -- --
1 s1 2 4 --
2 s2 3 3 3
3 s3 -- -- 3
4 s4 4 5 4
5 s5 6 5 4
6 s6 -- -- --

Code for Comment line in c in C++ Programming

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

int main()
{
    char stt[8][4] = {NULL, '7','8','9',
                        '0', '1', NULL, NULL,
                        '1', '2', '4', NULL,
                        '2', '3', '3', '3',
                        '3', NULL, NULL, '3',
                        '4', '4', '5', '4',
                        '5', '6', '5', '4',
                        '6', NULL, NULL, NULL};
    char ch, state = '0';
    char variable[40];
    int flag=0;

    cout<<"Input c Comment line : ";
    cin>>variable;

    for(int i=0; i<40 && variable[i] != NULL; i++)
    {
        if(variable[i] == '/')
        {
            ch = '7';
            flag=flag+1;
        }
        elseif(variable[i] == '*')
        {
            ch ='8';            
        }
        else
        {
            ch ='9';
        }

        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 comment line");
            getchar();
            exit(0);
        }
    }
    if (flag == 1)
    {    
        printf("Invalide comment line");
        getchar();
        exit(0);
    }
    else
    {
        printf("Valide Comment line");
    }
    getchar();
    return 0;
}
  
Share: 


Didn't find what you were looking for? Find more on Comment line in c Or get search suggestion and latest updates.

Rambert Fischer
Rambert Fischer author of Comment line 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!