This solution categorizes all tokens from a file into identifiers, operators, numbers, and special characters.

Sample Input File: code.txt

int x = 10;
float y = 3.14;
x++; y += 2.5;
result = x * y;

Sample Output File: report.txt

===== TOKEN ANALYSIS REPORT =====

IDENTIFIERS (6 unique, 7 total):
float 1
int 1
result 1
x 2
y 2

OPERATORS (5 unique, 6 total):
* 1
++ 1
+= 1
= 3

NUMBERS (3 unique, 3 total):
10 1
2.5 1
3.14 1

SPECIAL CHARACTERS (1 unique, 4 total):
; 4

TOTAL TOKENS: 20


Step 1: Define the Token Struct

#include <stdio.h>
#include <string.h>
#include <ctype.h>

struct Token {
    char value[50];
    int count;
};

Step 2: Helper Functions for Character Classification

int isIdentifierStart(char c) {
    return isalpha(c) || c == '_';
}

int isIdentifierChar(char c) {
    return isalnum(c) || c == '_';
}

int isOperatorChar(char c) {
    return (c == '+' || c == '-' || c == '*' || c == '/' || 
            c == '%' || c == '=' || c == '&' || c == '|');
}

int isSpecialChar(char c) {
    return (c == '.' || c == ',' || c == ';' || c == ':');
}

Step 3: Find Token in Array

Searches for a token in the array and returns its index, or -1 if not found.

int findToken(struct Token* tokens, int count, char* value) {
    for (int i = 0; i < count; i++) {
        if (strcmp(tokens[i].value, value) == 0) {
            return i;
        }
    }
    return -1;
}

Step 4: Add or Update Token

If token exists, increment count; otherwise, add new token.