#!/usr/bin/env cscript #include #include #include void cast_column_index(char *column_index_string, int column_index) { int needle_column_index_string = 0; char *reverse_column_index_string; memset(column_index_string, '\0', strlen(column_index_string)); while (column_index > 0) { column_index_string[needle_column_index_string] = column_index % (26 + 1) + 'A' - 1; if (column_index_string[needle_column_index_string] == 'A' - 1) { column_index_string[needle_column_index_string]++; } column_index /= 26 + 1; needle_column_index_string += 1; } reverse_column_index_string = strdup(column_index_string); for (; needle_column_index_string >= 0; needle_column_index_string--) { reverse_column_index_string[needle_column_index_string] = column_index_string[strlen(column_index_string) - needle_column_index_string - 1]; } strcpy(column_index_string, reverse_column_index_string); free(reverse_column_index_string); } int main(int argc, char *argv[]) { char column_index_string[3 + 1] = {0}; cast_column_index(column_index_string, 1); printf("1 → %s / A\n", column_index_string); cast_column_index(column_index_string, 25); printf("25 → %s / Y\n", column_index_string); cast_column_index(column_index_string, 26); printf("26 → %s / Z\n", column_index_string); cast_column_index(column_index_string, 27); printf("27 → %s / AA\n", column_index_string); cast_column_index(column_index_string, 52); printf("52 → %s / AY\n", column_index_string); cast_column_index(column_index_string, 53); printf("53 → %s / AZ\n", column_index_string); cast_column_index(column_index_string, 54); printf("54 → %s / BA\n", column_index_string); return 0; }