1
I have a dynamic vector of integers. For example:
1 2 4 6 8 9 10
I want to attach it to a string, like this, for example:
[B]:
And record this in a row of the file, then read the file with the following output, for example, assuming the program was run three times:
[B]: 1 2 4 6 8 9 10
[B]: 4 5 6 7 8
[B]: 3 6 7
I’ve been doing some research, but I couldn’t even get a clue how to do it, so I don’t have any code that’s in the way of doing that.
Can someone at least give me a way to do that? If you have a command, a demonstration, or whatever.
fprintf(arquivo, "[B]:"); for (int k = 0; k < n; k++) fprintf(arquivo, " %d", vetor[k]); fprintf(arquivo, "\n");
– pmg
Let’s eliminate the dynamic vector for now. Can you already create a file and write anything static inside it? I ask this because you can split your problem into parts. First understand how to open, write and close a file. After that, you leave for the 2nd step, which is to write the dynamic vector. I can say that if you do the 1st part, the 2nd part will be trivial.
– cantoni
What @pmg worked perfectly. Yes I know the basics of the file, I wasn’t reminded of the
fprintf
and thought there might be another way.– Leonardo
@pmg Is there no way to put as an answer? So we can vote and the answer can be accepted. With this we can document the question more clearly. Thank you!!! Ah, put an explanation in the code in comment form, if you accept my proposal.
– StillBuggin