#include <stdio.
h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
void scanChar(const char *text) {
printf("\nCharacter literals:\n");
bool state = false;
for (int pos = 0; text[pos] != '\0'; pos++) {
if (text[pos] == '\'') {
if (!state) {
state = true;
} else {
printf("'%c'\n", text[pos-1]);
state = false;
void scanPunct(const char *text) {
printf("\nPunctuation marks:\n");
for (int pos = 0; text[pos] != '\0'; pos++) {
if (ispunct(text[pos]) && text[pos] != '"' && text[pos] != '\'') {
switch (text[pos]) {
case '{': printf("{\n"); break;
case '}': printf("}\n"); break;
case '[': printf("[\n"); break;
case ']': printf("]\n"); break;
case '(': printf("(\n"); break;
case ')': printf(")\n"); break;
case ';': printf(";\n"); break;
case ':': printf(":\n"); break;
case ',': printf(",\n"); break;
case '.': printf(".\n"); break;
case '#': printf("#\n"); break;
case '_': printf("_\n"); break;
default: printf("%c\n", text[pos]); break;
void scanNum(const char *text) {
printf("\nDigits:\n");
for (int pos = 0; text[pos] != '\0'; pos++) {
if (isdigit(text[pos])) {
printf("%c\n", text[pos]);
void scanOp(const char *text) {
printf("\nOperators:\n");
for (int pos = 0; text[pos] != '\0'; pos++) {
switch (text[pos]) {
case '+': printf("+\n"); break;
case '-': printf("-\n"); break;
case '*': printf("*\n"); break;
case '/': printf("/\n"); break;
case '%': printf("%%\n"); break;
case '=': printf("=\n"); break;
case '<': printf("<\n"); break;
case '>': printf(">\n"); break;
case '&': printf("&\n"); break;
case '|': printf("|\n"); break;
case '!': printf("!\n"); break;
case '^': printf("^\n"); break;
void scanStr(const char *text) {
printf("\nStrings:\n");
bool state = false;
int mark = 0;
for (int pos = 0; text[pos] != '\0'; pos++) {
if (text[pos] == '"') {
if (!state) {
mark = pos;
state = true;
} else {
printf("\"");
for (int i = mark + 1; i < pos; i++) {
printf("%c", text[i]);
printf("\"\n");
state = false;
}
}
void scanKey(const char *text) {
const char *list[] = {
"auto", "break", "case", "char", "const", "continue", "default", "do", "double",
"else", "enum", "extern", "float", "for", "goto", "if", "int", "long", "register",
"return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef",
"union", "unsigned", "void", "volatile", "while"
};
const int max = sizeof(list) / sizeof(list[0]);
printf("\nKeywords:\n");
char temp[50];
int count = 0;
for (int pos = 0; text[pos] != '\0'; pos++) {
if (isalpha(text[pos]) || text[pos] == '_') {
temp[count++] = text[pos];
} else if (count > 0) {
temp[count] = '\0';
for (int i = 0; i < max; i++) {
if (strcmp(temp, list[i]) == 0) {
printf("%s\n", temp);
break;
count = 0;
}
if (count > 0) {
temp[count] = '\0';
for (int i = 0; i < max; i++) {
if (strcmp(temp, list[i]) == 0) {
printf("%s\n", temp);
break;
int main() {
char line[100];
printf("Enter the input string: ");
fgets(line, sizeof(line), stdin);
size_t size = strlen(line);
if (size > 0 && line[size - 1] == '\n') {
line[size - 1] = '\0';
scanKey(line);
scanNum(line);
scanOp(line);
scanStr(line);
scanChar(line);
scanPunct(line);
return 0;
}
Output: