C program to Identify Whether Given Line is Comment or Not

Aim:- Write a C program to Identify Whether Given Line is Comment or Not.

C Program Code:

             
#include<stdio.h>
#include<conio.h>
void main()
{
    char text[30];
    int i = 2, a = 0;
    clrscr();

    printf("\nWrite a C Program to Identify Whether a Given Line is a Commentor Not.");
    printf("\n\nEnter Text : ");
    gets(text);
    if(text[0] == '/')
    {
        if(text[1] == '/') {
            printf("\nIt is a Comment.");
        } 
        else if(text[1] == '*') 
        {
            for(i = 2; i <= 30; i++)
            {
                if(text[i] == '*' && text[i + 1] == '/')
                {
                    printf("\nIt is a Comment.");
                    a = 1;
                    break;
                }
                else {
                    continue;
                }
            }
            if(a == 0)
            {
                printf("\nIt is Not a Comment.");
            }
            else
            {
                printf("\nIt is Not a Comment.");
            }
        }
    }
    else
    {
        printf("\nIt is Not a Comment.");
    }
    getch();
}
        
            
        

Output:

Post a Comment

11 Comments

  1. above program doesnt work... Try below shortest program >>

    #include
    #include
    #include
    #include
    void main()
    {
    clrscr();
    printf("\nWrite a C Program to Identify Whether ....");
    printf("\n\nEnter Text : ");
    char text[50];
    scanf("%s",&text);
    if(text[0]=='/')
    {
    if(text[1]=='/')
    printf("\nIt is a single line Comment.");
    else if(text[1]=='*')
    printf("\nIt is a multi line Comment.");
    else
    printf("\nIt is Not a Comment.");
    }
    else
    {
    printf("\nIt is Not a Comment.");
    }
    printf("\n\nPress any key and enter to terminate");
    char pause[1];
    scanf("%s",&pause);
    }

    ReplyDelete
    Replies
    1. #include
      #include
      main()
      {
      char com[30];
      int i=2,a=0;
      printf("\n Enter comment:");
      gets(com);
      if(com[0]=='/') {
      if(com[1]=='/')
      printf("\n It is a comment");
      else if(com[1]=='*') {
      for(i=2;i<=30;i++)
      {
      if(com[i]=='*'&&com[i+1]=='/')
      {
      printf("\n It is a comment");
      a=1;
      break; }
      else
      continue; }
      if(a==0)
      printf("\n It is not a comment");
      }
      else
      printf("\n It is not a comment");
      }
      else
      printf("\n It is not a comment");
      getch();
      }

      try this

      Delete
  2. So a fruitful logo is a vital piece of your image personality. Just the organizations that can emerge from the group and rivalry prevail at last. logo design service

    ReplyDelete
  3. there was not error in compiling but when i run the program it have error

    ReplyDelete
  4. How to find comment line from a whole source code?

    ReplyDelete
  5. Many thanks for your kind invitation. I’ll join you.
    Would you like to play cards?
    Come to the party with me, please.
    See you soon...

    เครดิตฟรี

    เครดิตฟรี

    คาสิโน

    แจกเครดิตฟรี ฝากถอนง่าย

    ReplyDelete
  6. Looking for an app to rewrite sentences?Spinbot has apps that rewrite your essay efficiently. Improve your content instantly.

    ReplyDelete
  7. Thanks and that i have a keen offer: Whole House Renovation Cost Calculator Canada house renovation shows

    ReplyDelete