Skip to content

Commit bf2bbf2

Browse files
authored
Update c_remove_comments.c
If there's any ` " ` present in the block comment,the program prints the all characters in that block_comment starting with the ` " `. For example: int main(void) { /** *" * */ the output will contain: int main(void) { " * */ --------------------------------------------------------------------- The if-statement: 55: if(!block_comment) removes this bug.
1 parent 9e36a2a commit bf2bbf2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

chapter_1/exercise_1_23/c_remove_comments.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ void remove_comments(char str[], char no_com_str[])
5252
int i = 0, j = 0;
5353
while (str[i] != '\0')
5454
{
55-
if (!in_quote && str[i] == '"')
55+
if (!block_comment)
56+
{
57+
if (!in_quote && str[i] == '"')
5658
{
5759
in_quote = TRUE;
5860
}
5961
else if (in_quote && str[i] == '"')
6062
{
6163
in_quote = FALSE;
6264
}
65+
}
6366

6467
if (!in_quote)
6568
{

0 commit comments

Comments
 (0)