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();
}
Also Read - C program to count total words in text
11 Comments
above program doesnt work... Try below shortest program >>
ReplyDelete#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);
}
thanks
Delete#include
Delete#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
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
ReplyDeletethere was not error in compiling but when i run the program it have error
ReplyDeleteHow to find comment line from a whole source code?
ReplyDeleteMany thanks for your kind invitation. I’ll join you.
ReplyDeleteWould you like to play cards?
Come to the party with me, please.
See you soon...
เครดิตฟรี
เครดิตฟรี
คาสิโน
แจกเครดิตฟรี ฝากถอนง่าย
Ulaebaniso Angie Andrews https://wakelet.com/wake/L-dz_FwdqwlqJLmYGYKcG
ReplyDeletecurekdedoub
MnaliZriabu-Savannah Charlie Horne WonderShare Recoverit
ReplyDeleteDr.Web Security Space
WinZip
ilamriada
Looking for an app to rewrite sentences?Spinbot has apps that rewrite your essay efficiently. Improve your content instantly.
ReplyDeleteThanks and that i have a keen offer: Whole House Renovation Cost Calculator Canada house renovation shows
ReplyDelete