Dff

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

// Function to check if a line is a comment
void checkComment(char line[]) {
    // Check for single-line comment
    if (strncmp(line, "//", 2) == 0) {
        printf("The line is a single-line comment.\n");
    }
    // Check for multi-line comment (both opening and closing)
    else if (strncmp(line, "/*", 2) == 0 && strstr(line, "*/") != NULL) {
        printf("The line is a multi-line comment.\n");
    }
    // Otherwise, it's not a comment
    else {
        printf("The line is not a comment.\n");
    }
}

int main() {
    char line[200];

    // Input the line to be checked
    printf("Enter a line of code: ");
    fgets(line, sizeof(line), stdin); // To get input with spaces

    // Remove the trailing newline character if present
    line[strcspn(line, "\n")] = 0;

    // Check if the line is a comment
    checkComment(line);

    return 0;
}
Leave a Comment