Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ /me gots it and needs a bit o help!

  • 10-06-2001 4:35pm
    #1
    Closed Accounts Posts: 822 ✭✭✭


    ok i just want to find out basic stuff..
    how to open a text file called "hi.txt"
    and how to delete it with the address something like : C:\windows\desktop\folders\hi.txt etc..

    any other useful pointers would be welcome..
    thanks wink.gif


Comments

  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    //Hi,

    //Ok to open a file in C/C++ do the following

    FILE openFile(char *filename)
    {
    FILE fp;
    if((fp = fopen(filename, "r+")) != NULL)
    return fp;
    else
    return NULL;
    }

    /* the above function will open a specified file for reading + writing if successful. To write to the file you can simply use
    */

    fprintf(fp, "My name is: %s", myName);

    // and to read

    fscanf(fp, "%s", input);

    /* All the above functions apart from my own are defined in <stdio.h>, I know that is an ANSI C & not C++ function library, but it doesn't matter it will work anyway.

    To delete a file is simple, all you have to do is call the remove() method defined in <stdio.h> and pass it the path to the file. NOTE: you probably already know this but just remember that the '\' character is an escape character and you will need "\\" to represent a '\' in C,C++ & Java.

    Hope that helps

    ;-phobos-) */
    */



    [This message has been edited by phobos (edited 10-06-2001).]


  • Registered Users, Registered Users 2 Posts: 2,660 ✭✭✭Baz_


    FILE address must be held in FILE pointers, and also the memory has to be new'd (in c++) in order that it doesn't get returned to the OS when the function ends. I was going to do a longer reply but I sneezed and hit the clear fields button by mistake so I cut it short, sorry if it appears *****y, it's not meant to.


  • Closed Accounts Posts: 822 ✭✭✭Kastro


    yup thanks a lot,
    very useful smile.gif
    1 thing i forgot is to ask how you shut down the puter..!


Advertisement