You can just create an array of structs, as the other answer described.
Once you have the struct
definition:
typedef struct {
char letter;
int number;
} record_t;
Then you can create an array of structs like this:
record_t records[26]; /* 26 letters in alphabet, can be anything you want */
Using a 2D array would be unnecessary, as wrapping the letter and number in a struct
would be easier to handle.
In terms of reading your file, you can just read with fscanf()
until 2
values are not found.
Here is some basic code you can use:
#include <stdio.h>
#include <stdlib.h>
#define NUMLETTERS 26
typedef struct {
char letter;
int number;
} record_t;
int main(void) {
FILE *fp;
record_t records[NUMLETTERS];
size_t count = 0;
fp = fopen("letters.csv", "r");
if (fp == NULL) {
fprintf(stderr, "Error reading file\n");
return 1;
}
while (fscanf(fp, " %c,%d", &records[count].letter, &records[count].number) == 2) {
count++;
}
for (size_t i = 0; i < count; i++) {
printf("%c,%d\n", records[i].letter, records[i].number);
}
fclose(fp);
return 0;
}