Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Can any one help me me? need a c program to open a file using c

  1. Jul 19, 2008 #1
    can any one help me me???? need a c program to open a file using c

    pls can any one send me a c programing code for opening a files
     
  2. jcsd
  3. Jul 19, 2008 #2

    Defennder

    User Avatar
    Homework Helper

  4. Jul 19, 2008 #3

    zyh

    User Avatar

  5. Jul 21, 2008 #4

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    Re: can any one help me me???? need a c program to open a file using c

    The simplest way to open a file is "fopen(Filename, mode)" where Filename is the file name as a string and mode is string such as "r" for "read only", "w" for "write", "a" for "append" (add to end of file), and a number of others.
    That returns a pointer to the open file that you would then use in reading or writing to the file.

    For example,
    FILE *f= fopen("myFile","r");

    makes f a pointer that can be used to read from "myFile".

    You could then use "fread(buffer, 10,10, f)" to read up to 10 bytes from the file to the variable "buffer" (which you would declare as a pointer to the correct type of variable) or you could use fscanf(f, ...) to read a formatted string just as you would with "scanf".
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Can any one help me me? need a c program to open a file using c
  1. C++ - File opening (Replies: 3)

Loading...