edit for simplicity at the bottom
I've got a little problem in my current school project. (plain c) The project itself is a little quiz inside a console, and I'm trying to store the questions, their answers and assigned points. The file i want to store it in, already has text in it which will be scanned through for its total number of lines, and then will be completely wiped and written to again.
This is the File itself should look at the end:
1#Excel?#Good#Bad#Miserable#Awesome#1#5
2#Word?#Good#Bad#Miserable#Awesome#1#10
3#Powerpoint?#Good#Bad#Miserable#Awesome#4#15
(Number of the Question, the Question itself, 4 answers, the number of the right answer, and the assigned points)
The variables themselves are like this (I'll just show one for simplicity, they all are the same type)
char frageinhalt[255][255];
there are two more variables in my code below, (lines & i) those are both simple integers. lines is the total amount of lines the existing file has (reduced by one in the code below, because the last line is empty).
This char array holds the Questions themselves,
frageinhalt[0] = "Excel?"
frageinhalt[1] = "Word?"
and so on.
and this is how i want to store it
for(i=0; i<lines-1; i++) {
fprintf(datei_ptr, "%i#%s\n",i+1,frageinhalt[i]);
}
What's the problem with this?
Or is there a way to access and edit a specific line inside a file (in plain c) which I don't know of?
#########edit#########
to explain it simply (well atleast let me try): I've got a variable
char frageinhalt[255][255];
which contains simple sentences (lets say 10) like
What is the capital of Germany?
I now want to write these sentences (in addition to an ID) into a .txt file, each sentence in its own line, like this:
1#What is the capital of Germany?
2#What is the capital of France?
This is the code i tried:
for(i=0; i=10; i++) {
fprintf(filepointer, "%i#%s\n",i+1,frageinhalt[i]);
}
but it doesn't work. Why? And how can I fix it?