-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalid_comment.cpp
42 lines (36 loc) · 979 Bytes
/
valid_comment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
int main()
{
char com[100]; // Increased the buffer size to handle larger comments
int i = 2, a = 0;
printf("\tEnter comment: ");
scanf("%99s", com); // Prevent buffer overflow by limiting input to 99 characters
int len = strlen(com);
if (com[0] == '/')
{
if (com[1] == '/')
{
printf("\tIt is a valid comment\n");
}
else if (com[1] == '*')
{
for (i = 2; i < len - 1; i++)
{
if (com[i] == '*' && com[i + 1] == '/')
{
printf("\tIt is a valid comment\n");
a = 1;
break;
}
}
if (a == 0)
printf("\tIt is not a valid comment\n");
}
else
printf("\tIt is not a valid comment\n");
}
else
printf("\tIt is not a valid comment\n");
return 0;
}