I do not really know how to continue with this, could someone help?
Comments are treated as whitespace. Each comment is replaced by one space character, or by several newline characters, depending on how the comment was written. Note that the interior of character constants (like 'a') and string literals (like "a") do not contain comments, so this pass is more complex than the first three. You need to do some elements of tokenization here, but only to recognize the beginning and end of character constants, string literals, and the two forms of comments.
The string literal "/* xyz */" looks like it contains a comment, but it doesn't, so don't change the string. It goes to the output of this pass as-is.
The two forms of comment are
/* extending to the first */
// extending to the end of line
The /**/ form can extend across source code lines. It should be replaced with one space character if all on one line, or with one or more newline characters if on multiple lines (as a partial attempt to preserve the original number of lines).
Comments are not recognized within other comments. The first example (a nested comment) is illegal in Standard C and the second is one comment not two, The third example is not terminated (it might be terminated on a later line).
/* /* something */ */
// /* something */
/* // something
Code:
# include <stdio.h>
int main(){
int c0, c1;
bool notString = false;
c0 = getc(stdin); c1 = getc(stdin), c2 = getc(stdin);
while (c0 != EOF) {
int shift = 1;
if(c0 == '"'){
input(c0);}
else if (c0 == '/' && c1 == '*'){
c0 = '\n';
shift = 2;
printf("%c",c0);}
else if (c0 == '/' && c1 == '/'){
c0 = ' ';
shift = 2;
printf("%c",c0);}
if (shift == 1)
{ c0 = c1; c1 = getc(stdin); }
else /* shift == 2 */
{ c0 = getc(stdin); c1 = getc(stdin); }
}
return 0;}
void input (char c)
{
do {
c = getchar();
putchar (c);
} while (c != '"');
}