Thread: More on files.

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    17
    Rep Power
    0

    More on files.


    I'm just testing to make sure I'm understanding this and I have a few questions.

    #include<stdio.h>

    int main()
    {
    int i,ii;
    FILE *RandW;
    char fname[] = "Success.txt";
    RandW = fopen(fname,"w");
    fprintf(RandW,"%d %d",56,23);
    fclose(RandW);
    RandW = fopen(fname,"r");
    fscanf(RandW,"%d %d",&i,&ii);
    fclose(RandW);
    printf("%d %d is in Success.txt",i,ii);
    getchar();
    return 0;
    }
    That's my code. It works, but I have to to ask. when using fscanf, is the only way you can find text in the file is if you add a variable(i,ii) to the program.

    also, I saw a word called append as one of the second arguments in fopen(). What does append mean? Reading reads input, writing shows output but what's append? Does it check to make sure?

    Thanks again.

    Comments on this post

    • salem disagrees : 10+ posts and still no code tags - are you paying any attention?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    148
    Rep Power
    139
    In addition to what Salem said, read also the documentation.
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    If your compiler did not come with a help file, then Google on man page fopen for the documentation for fopen. You can also Google for the man pages of any other C Library function.

IMN logo majestic logo threadwatch logo seochat tools logo