What does the expression "a+t" mean in the second parameter of fopen in C?

Asked

Viewed 157 times

7

I was coming across a code here and I was curious about this excerpt:

FILE *fp = fopen("Agenda.txt","a+t");

What’s the point of "a+t"?

  • Look, the "t" I don’t know, because I don’t know much C. But I can assure you that a means: "always add content from the last line of the file"

  • That’s right, thank you!!

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

2 answers

8

This is the access mode to the file being opened. "a+" indicates that you can only add data at the end of the file (append) and that can be read as well ("+"). Recording must always be made official with fflush().

"t" indicates that you can only use text, but this is not standard C. Only some specific compiler accepts on specific platform, but this is considers a undefined behavior.

Documentation.

  • How the file is opened with fopen(), has to be effected using fflush().

  • @Wtrmute yes, I think it was just typo, thank you.

2

According to the website of fopen.

"a+t" or "at+" it opens a text file in read or update mode (adding the new information at the end of the file).

  • Thank you very much!

  • The "text mode" refers to the translation of car returns, which it converts when reading from CR LF for LF, and the opposite when writing. A flag opposite, b, explicitly disables this conversion.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.