Commit b68740f9 authored by jinny.wilkin's avatar jinny.wilkin

reads csv, generates 721 pokemon entries

parent 27d1d5df
No preview for this file type
......@@ -3,12 +3,12 @@
#include <stdbool.h>
#include <stdlib.h>
#define MAXCHAR 1000
typedef struct Pokemon{
int id, height, weight;
char name[11], species[21], type1[8], type2[8], ability[13], evolveTo[11], evolveFrom[11];
bool dimorphic;
char name[12], species[22], type1[9], type2[9], ability[14], evolveTo[12], evolveFrom[12], dimorphic[6];
} Pokemon;
typedef struct Trainers{
......@@ -21,7 +21,7 @@ typedef struct Pokedex{
Trainers trainers[];
} Pokedex;
int main(void){
int populateDex(){
FILE *fp;
char row[MAXCHAR];
int n = 1;
......@@ -29,19 +29,39 @@ int main(void){
fp = fopen("pokedexREF.csv", "r");
;
Pokemon pokelist[721];
int read = 0;
int records = 0;
while (!feof(fp)){
fgets(row, n, fp);
n++;
read = fscanf(fp, "%d,%11[^,],%8[^,],%8[^,],%13[^,],%d,%d,%5[^,],%11[^,],%11[^,],%21[^\n]\n",
&pokelist[records].id, pokelist[records].name, pokelist[records].type1, pokelist[records].type2, pokelist[records].ability, &pokelist[records].height,
&pokelist[records].weight, pokelist[records].dimorphic, pokelist[records].evolveTo, pokelist[records].evolveFrom, pokelist[records].species);
holder = strtok(row, ",");
if (read == 11) records++;
while(holder != NULL){
printf("Token: %s\n", holder);
holder = strtok(NULL, ",");
if(read != 11){
printf("File Format Error");
printf("\n%d records read.\n", records);
printf("%d %s %s %s %s %s %d %d %s %s %s\n", pokelist[2].id, pokelist[2].name, pokelist[2].species, pokelist[2].type1, pokelist[2].type2, pokelist[2].ability, pokelist[2].height,
pokelist[2].weight, pokelist[2].dimorphic, pokelist[2].evolveTo, pokelist[2].evolveFrom);
return 1;
}
}
return 0;
fclose(fp);
printf("\n%d records read.\n", records);
}
int main(void){
printf("Loading Pokedex, please wait...");
populateDex();
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment