What is the difference between r+ and a+ in fopen?












2















I don't understand what is the practical difference between r+ and a+ in fopen in c. Can someone help me?










share|improve this question



























    2















    I don't understand what is the practical difference between r+ and a+ in fopen in c. Can someone help me?










    share|improve this question

























      2












      2








      2








      I don't understand what is the practical difference between r+ and a+ in fopen in c. Can someone help me?










      share|improve this question














      I don't understand what is the practical difference between r+ and a+ in fopen in c. Can someone help me?







      c file io






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 16:08









      ZaratrutaZaratruta

      330316




      330316
























          3 Answers
          3






          active

          oldest

          votes


















          4














          r+ will open a file for reading and writing. It will fail if the file does not exist. fseek can be used to read and write anywhere in the file.



          w+ will open a file for reading and writing. It will create the file if the file does not exist, and destroy and recreate the file if the file does exist. fseek can be used to read anywhere in the file.



          a+ will open a file for reading and writing. It will create the file if the file does not exist. fseek can be used to read anywhere in the file, but writes will always append to the end of the file regardless of any calls to fseek.






          share|improve this answer































            1














            Taken this from fopen man page




            • r Open text file for reading. The stream is positioned at the
              beginning of the file.


            • r+ Open for reading and writing. The stream is positioned at the
              beginning of the file.


            • w Truncate file to zero length or create text file for writing.
              The stream is positioned at the beginning of the file.


            • w+ Open for reading and writing. The file is created if it does
              not exist, otherwise it is truncated. The stream is
              positioned at the beginning of the file.


            • a Open for appending (writing at end of file). The file is
              created if it does not exist. The stream is positioned at the
              end of the file.


            • a+ Open for reading and appending (writing at end of file). The
              file is created if it does not exist. The initial file
              position for reading is at the beginning of the file, but
              output is always appended to the end of the file.



            I decided to give an example for a future reference.First of all FILE* fp will be a pointer to a stream, not the actual data of the file in the hard disk.So when fopen is invoked , it's invoked on a stream, not the file.Just keep in mind that one file can have multiple streams.
            What + is (b is also acceptable here, i.e. r+ == rb) here, is simply an 'update'.This has to do with the way that system writes in a file.A file can be written either if data erased and written as a whole, or change just the data that changed.For example if we need to update "Today is monday" to "TODAY is Monday" either we purge the sentence and write it again.But if we UPDATE we just change o to O, n to N,a to A,y to Y and m to M.



            To the actual example, lets assume that we have an empty file and we call
            (I have the whole code,in case you want to take it and test your self)



            int main() {
            FILE * fp;

            if(fp==NULL)
            {
            return -1;
            }

            fp = fopen("file.txt", "r+");
            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
            fflush(fp);
            fclose(fp);

            fp = fopen("file.txt", "r+");
            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
            fflush(fp);
            fclose(fp);

            fp = fopen("file.txt", "r+");
            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
            fflush(fp);
            fclose(fp);

            return(0);
            }


            Also this question has already answered here



            This will give us a file like:




            This is test ticket 10003




            which is normal because the first call wrote




            This is test ticket 10001




            the second call changed 1 to 2 and the third call changed 2 to 3.
            Now if we change those 3 fopen calls like:



                fp = fopen("file.txt", "a+");
            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
            fflush(fp);
            fclose(fp);

            fp = fopen("file.txt", "a+");
            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
            fflush(fp);
            fclose(fp);

            fp = fopen("file.txt", "a+");
            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
            fflush(fp);
            fclose(fp);


            We will get




            This is test ticket 10001This is test ticket 10002This is
            test ticket 10003




            as each call appended.






            share|improve this answer

































              0














              yet another reference www.cplusplus.com





              • "r" read: Open file for input operations. The file must exist.


              • "w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.


              • "a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist.


              • "r+" read/update: Open a file for update (both for input and output). The file must exist.


              • "w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.


              • "a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.






              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285029%2fwhat-is-the-difference-between-r-and-a-in-fopen%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                4














                r+ will open a file for reading and writing. It will fail if the file does not exist. fseek can be used to read and write anywhere in the file.



                w+ will open a file for reading and writing. It will create the file if the file does not exist, and destroy and recreate the file if the file does exist. fseek can be used to read anywhere in the file.



                a+ will open a file for reading and writing. It will create the file if the file does not exist. fseek can be used to read anywhere in the file, but writes will always append to the end of the file regardless of any calls to fseek.






                share|improve this answer




























                  4














                  r+ will open a file for reading and writing. It will fail if the file does not exist. fseek can be used to read and write anywhere in the file.



                  w+ will open a file for reading and writing. It will create the file if the file does not exist, and destroy and recreate the file if the file does exist. fseek can be used to read anywhere in the file.



                  a+ will open a file for reading and writing. It will create the file if the file does not exist. fseek can be used to read anywhere in the file, but writes will always append to the end of the file regardless of any calls to fseek.






                  share|improve this answer


























                    4












                    4








                    4







                    r+ will open a file for reading and writing. It will fail if the file does not exist. fseek can be used to read and write anywhere in the file.



                    w+ will open a file for reading and writing. It will create the file if the file does not exist, and destroy and recreate the file if the file does exist. fseek can be used to read anywhere in the file.



                    a+ will open a file for reading and writing. It will create the file if the file does not exist. fseek can be used to read anywhere in the file, but writes will always append to the end of the file regardless of any calls to fseek.






                    share|improve this answer













                    r+ will open a file for reading and writing. It will fail if the file does not exist. fseek can be used to read and write anywhere in the file.



                    w+ will open a file for reading and writing. It will create the file if the file does not exist, and destroy and recreate the file if the file does exist. fseek can be used to read anywhere in the file.



                    a+ will open a file for reading and writing. It will create the file if the file does not exist. fseek can be used to read anywhere in the file, but writes will always append to the end of the file regardless of any calls to fseek.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 13 '18 at 16:14









                    contrapantscontrapants

                    600214




                    600214

























                        1














                        Taken this from fopen man page




                        • r Open text file for reading. The stream is positioned at the
                          beginning of the file.


                        • r+ Open for reading and writing. The stream is positioned at the
                          beginning of the file.


                        • w Truncate file to zero length or create text file for writing.
                          The stream is positioned at the beginning of the file.


                        • w+ Open for reading and writing. The file is created if it does
                          not exist, otherwise it is truncated. The stream is
                          positioned at the beginning of the file.


                        • a Open for appending (writing at end of file). The file is
                          created if it does not exist. The stream is positioned at the
                          end of the file.


                        • a+ Open for reading and appending (writing at end of file). The
                          file is created if it does not exist. The initial file
                          position for reading is at the beginning of the file, but
                          output is always appended to the end of the file.



                        I decided to give an example for a future reference.First of all FILE* fp will be a pointer to a stream, not the actual data of the file in the hard disk.So when fopen is invoked , it's invoked on a stream, not the file.Just keep in mind that one file can have multiple streams.
                        What + is (b is also acceptable here, i.e. r+ == rb) here, is simply an 'update'.This has to do with the way that system writes in a file.A file can be written either if data erased and written as a whole, or change just the data that changed.For example if we need to update "Today is monday" to "TODAY is Monday" either we purge the sentence and write it again.But if we UPDATE we just change o to O, n to N,a to A,y to Y and m to M.



                        To the actual example, lets assume that we have an empty file and we call
                        (I have the whole code,in case you want to take it and test your self)



                        int main() {
                        FILE * fp;

                        if(fp==NULL)
                        {
                        return -1;
                        }

                        fp = fopen("file.txt", "r+");
                        fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                        fflush(fp);
                        fclose(fp);

                        fp = fopen("file.txt", "r+");
                        fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                        fflush(fp);
                        fclose(fp);

                        fp = fopen("file.txt", "r+");
                        fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                        fflush(fp);
                        fclose(fp);

                        return(0);
                        }


                        Also this question has already answered here



                        This will give us a file like:




                        This is test ticket 10003




                        which is normal because the first call wrote




                        This is test ticket 10001




                        the second call changed 1 to 2 and the third call changed 2 to 3.
                        Now if we change those 3 fopen calls like:



                            fp = fopen("file.txt", "a+");
                        fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                        fflush(fp);
                        fclose(fp);

                        fp = fopen("file.txt", "a+");
                        fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                        fflush(fp);
                        fclose(fp);

                        fp = fopen("file.txt", "a+");
                        fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                        fflush(fp);
                        fclose(fp);


                        We will get




                        This is test ticket 10001This is test ticket 10002This is
                        test ticket 10003




                        as each call appended.






                        share|improve this answer






























                          1














                          Taken this from fopen man page




                          • r Open text file for reading. The stream is positioned at the
                            beginning of the file.


                          • r+ Open for reading and writing. The stream is positioned at the
                            beginning of the file.


                          • w Truncate file to zero length or create text file for writing.
                            The stream is positioned at the beginning of the file.


                          • w+ Open for reading and writing. The file is created if it does
                            not exist, otherwise it is truncated. The stream is
                            positioned at the beginning of the file.


                          • a Open for appending (writing at end of file). The file is
                            created if it does not exist. The stream is positioned at the
                            end of the file.


                          • a+ Open for reading and appending (writing at end of file). The
                            file is created if it does not exist. The initial file
                            position for reading is at the beginning of the file, but
                            output is always appended to the end of the file.



                          I decided to give an example for a future reference.First of all FILE* fp will be a pointer to a stream, not the actual data of the file in the hard disk.So when fopen is invoked , it's invoked on a stream, not the file.Just keep in mind that one file can have multiple streams.
                          What + is (b is also acceptable here, i.e. r+ == rb) here, is simply an 'update'.This has to do with the way that system writes in a file.A file can be written either if data erased and written as a whole, or change just the data that changed.For example if we need to update "Today is monday" to "TODAY is Monday" either we purge the sentence and write it again.But if we UPDATE we just change o to O, n to N,a to A,y to Y and m to M.



                          To the actual example, lets assume that we have an empty file and we call
                          (I have the whole code,in case you want to take it and test your self)



                          int main() {
                          FILE * fp;

                          if(fp==NULL)
                          {
                          return -1;
                          }

                          fp = fopen("file.txt", "r+");
                          fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                          fflush(fp);
                          fclose(fp);

                          fp = fopen("file.txt", "r+");
                          fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                          fflush(fp);
                          fclose(fp);

                          fp = fopen("file.txt", "r+");
                          fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                          fflush(fp);
                          fclose(fp);

                          return(0);
                          }


                          Also this question has already answered here



                          This will give us a file like:




                          This is test ticket 10003




                          which is normal because the first call wrote




                          This is test ticket 10001




                          the second call changed 1 to 2 and the third call changed 2 to 3.
                          Now if we change those 3 fopen calls like:



                              fp = fopen("file.txt", "a+");
                          fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                          fflush(fp);
                          fclose(fp);

                          fp = fopen("file.txt", "a+");
                          fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                          fflush(fp);
                          fclose(fp);

                          fp = fopen("file.txt", "a+");
                          fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                          fflush(fp);
                          fclose(fp);


                          We will get




                          This is test ticket 10001This is test ticket 10002This is
                          test ticket 10003




                          as each call appended.






                          share|improve this answer




























                            1












                            1








                            1







                            Taken this from fopen man page




                            • r Open text file for reading. The stream is positioned at the
                              beginning of the file.


                            • r+ Open for reading and writing. The stream is positioned at the
                              beginning of the file.


                            • w Truncate file to zero length or create text file for writing.
                              The stream is positioned at the beginning of the file.


                            • w+ Open for reading and writing. The file is created if it does
                              not exist, otherwise it is truncated. The stream is
                              positioned at the beginning of the file.


                            • a Open for appending (writing at end of file). The file is
                              created if it does not exist. The stream is positioned at the
                              end of the file.


                            • a+ Open for reading and appending (writing at end of file). The
                              file is created if it does not exist. The initial file
                              position for reading is at the beginning of the file, but
                              output is always appended to the end of the file.



                            I decided to give an example for a future reference.First of all FILE* fp will be a pointer to a stream, not the actual data of the file in the hard disk.So when fopen is invoked , it's invoked on a stream, not the file.Just keep in mind that one file can have multiple streams.
                            What + is (b is also acceptable here, i.e. r+ == rb) here, is simply an 'update'.This has to do with the way that system writes in a file.A file can be written either if data erased and written as a whole, or change just the data that changed.For example if we need to update "Today is monday" to "TODAY is Monday" either we purge the sentence and write it again.But if we UPDATE we just change o to O, n to N,a to A,y to Y and m to M.



                            To the actual example, lets assume that we have an empty file and we call
                            (I have the whole code,in case you want to take it and test your self)



                            int main() {
                            FILE * fp;

                            if(fp==NULL)
                            {
                            return -1;
                            }

                            fp = fopen("file.txt", "r+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "r+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "r+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                            fflush(fp);
                            fclose(fp);

                            return(0);
                            }


                            Also this question has already answered here



                            This will give us a file like:




                            This is test ticket 10003




                            which is normal because the first call wrote




                            This is test ticket 10001




                            the second call changed 1 to 2 and the third call changed 2 to 3.
                            Now if we change those 3 fopen calls like:



                                fp = fopen("file.txt", "a+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "a+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "a+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                            fflush(fp);
                            fclose(fp);


                            We will get




                            This is test ticket 10001This is test ticket 10002This is
                            test ticket 10003




                            as each call appended.






                            share|improve this answer















                            Taken this from fopen man page




                            • r Open text file for reading. The stream is positioned at the
                              beginning of the file.


                            • r+ Open for reading and writing. The stream is positioned at the
                              beginning of the file.


                            • w Truncate file to zero length or create text file for writing.
                              The stream is positioned at the beginning of the file.


                            • w+ Open for reading and writing. The file is created if it does
                              not exist, otherwise it is truncated. The stream is
                              positioned at the beginning of the file.


                            • a Open for appending (writing at end of file). The file is
                              created if it does not exist. The stream is positioned at the
                              end of the file.


                            • a+ Open for reading and appending (writing at end of file). The
                              file is created if it does not exist. The initial file
                              position for reading is at the beginning of the file, but
                              output is always appended to the end of the file.



                            I decided to give an example for a future reference.First of all FILE* fp will be a pointer to a stream, not the actual data of the file in the hard disk.So when fopen is invoked , it's invoked on a stream, not the file.Just keep in mind that one file can have multiple streams.
                            What + is (b is also acceptable here, i.e. r+ == rb) here, is simply an 'update'.This has to do with the way that system writes in a file.A file can be written either if data erased and written as a whole, or change just the data that changed.For example if we need to update "Today is monday" to "TODAY is Monday" either we purge the sentence and write it again.But if we UPDATE we just change o to O, n to N,a to A,y to Y and m to M.



                            To the actual example, lets assume that we have an empty file and we call
                            (I have the whole code,in case you want to take it and test your self)



                            int main() {
                            FILE * fp;

                            if(fp==NULL)
                            {
                            return -1;
                            }

                            fp = fopen("file.txt", "r+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "r+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "r+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                            fflush(fp);
                            fclose(fp);

                            return(0);
                            }


                            Also this question has already answered here



                            This will give us a file like:




                            This is test ticket 10003




                            which is normal because the first call wrote




                            This is test ticket 10001




                            the second call changed 1 to 2 and the third call changed 2 to 3.
                            Now if we change those 3 fopen calls like:



                                fp = fopen("file.txt", "a+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10001);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "a+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10002);
                            fflush(fp);
                            fclose(fp);

                            fp = fopen("file.txt", "a+");
                            fprintf(fp, "%s %s %s %d", "This", " is ", "test ticket ", 10003);
                            fflush(fp);
                            fclose(fp);


                            We will get




                            This is test ticket 10001This is test ticket 10002This is
                            test ticket 10003




                            as each call appended.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 14 '18 at 13:21

























                            answered Nov 13 '18 at 16:23









                            Tsakiroglou FotisTsakiroglou Fotis

                            512316




                            512316























                                0














                                yet another reference www.cplusplus.com





                                • "r" read: Open file for input operations. The file must exist.


                                • "w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.


                                • "a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist.


                                • "r+" read/update: Open a file for update (both for input and output). The file must exist.


                                • "w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.


                                • "a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.






                                share|improve this answer




























                                  0














                                  yet another reference www.cplusplus.com





                                  • "r" read: Open file for input operations. The file must exist.


                                  • "w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.


                                  • "a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist.


                                  • "r+" read/update: Open a file for update (both for input and output). The file must exist.


                                  • "w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.


                                  • "a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    yet another reference www.cplusplus.com





                                    • "r" read: Open file for input operations. The file must exist.


                                    • "w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.


                                    • "a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist.


                                    • "r+" read/update: Open a file for update (both for input and output). The file must exist.


                                    • "w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.


                                    • "a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.






                                    share|improve this answer













                                    yet another reference www.cplusplus.com





                                    • "r" read: Open file for input operations. The file must exist.


                                    • "w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.


                                    • "a" append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist.


                                    • "r+" read/update: Open a file for update (both for input and output). The file must exist.


                                    • "w+" write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.


                                    • "a+" append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 13 '18 at 16:27









                                    static_caststatic_cast

                                    6411618




                                    6411618






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285029%2fwhat-is-the-difference-between-r-and-a-in-fopen%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Bressuire

                                        Vorschmack

                                        Quarantine