Untitled

 avatar
unknown
plain_text
7 days ago
794 B
2
Indexable
#include <stdio.h>
#include <string.h>

int isSingleLineComment(char input[]) {
    return (strncmp(input, "//", 2) == 0);
}

int isMultiLineComment(char input[]) {
    return (strncmp(input, "/*", 2) == 0 && 
            strstr(input, "*/") != NULL);
}

int main() {
    char input[1000];

    printf("Enter a comment: ");
    fgets(input, sizeof(input), stdin); // Use fgets to read entire line including spaces

    // Remove trailing newline if present
    input[strcspn(input, "\n")] = '\0';

    if (isSingleLineComment(input)) {
        printf("It is a single-line comment.\n");
    } else if (isMultiLineComment(input)) {
        printf("It is a multi-line comment.\n");
    } else {
        printf("It is not a valid comment.\n");
    }

    return 0;
}
Editor is loading...
Leave a Comment