Everything in C right here...
I wanna read a csv file with fgets separate for each row. I am doing this by going through my csv file, read a specific row, save this into my array and grow my continuous variable.
Im wanna write a program to convert a csv file into a JSON with specific headers for specific rows, but this is a long way to go...
This is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "menu.h"
int main() {
printf("\n\n\nCode starts...\n");
int i = 0;
int j = 0;
char content[1000];
char * contentArray[2][9];
FILE * regel1 = fopen("Regel-1.csv","r");
while(!feof(regel1)){
fgets(content, sizeof(content), regel1);
contentArray[i][j] = content;
printf("\nThis is contentArray[%i][0]: %s\n", i, contentArray[i][0]);
i++;
}
printf("\nWhile-Loop finished...\n");
for(int n = 0; n<=1; n++){
printf("\nThat is contentArray[%i][0]: %s\n", n, contentArray[n][0]);
}
fclose(regel1);
return 0;
}
As you can see in my output, it first saves the two different lines of the csv file into the array but then...as I know from testing...overwrites the first array entry with the fgets...
Code starts...
This is contentArray[0][0]: ME;Wie ist der übliche Abstand der gegnerischen Spieler bei einer mit dem Fuß ausgeführten Spielfortsetzung, z.B. dem Anstoß?;9 Meter;9,15 Meter;10 Meter;2;2;;;
This is contentArray[1][0]: ME;Welche Art von Freistoß wird an einem beliebigen Punkt innerhalb des Torraums ausgeführt?;Direkte und Indirekte Freistöße für die verteidigende Mannschaft.;Direkte Freistöße für die angreifende Mannschaft.;Indirekte Freistöße für die angreifende Mannschaft.;1;2;;;
While-Loop finished...
That is contentArray[0][0]: ME;Welche Art von Freistoß wird an einem beliebigen Punkt innerhalb des Torraums ausgeführt?;Direkte und Indirekte Freistöße für die verteidigende Mannschaft.;Direkte Freistöße für die angreifende Mannschaft.;Indirekte Freistöße für die angreifende Mannschaft.;1;2;;;
That is contentArray[1][0]: ME;Welche Art von Freistoß wird an einem beliebigen Punkt innerhalb des Torraums ausgeführt?;Direkte und Indirekte Freistöße für die verteidigende Mannschaft.;Direkte Freistöße für die angreifende Mannschaft.;Indirekte Freistöße für die angreifende Mannschaft.;1;2;;;
I would really appreciate your help.
Thanks in advance
GMOSS