Stream input and output functions, C/C++ Programming

Assignment Help:

  Within C we access external devices by means of a pointer i.e. address. The address could point to any memory mapped device i.e. Ram, Rom, Duart, Disk drives etc. Therefore there is no difference between accessing area in Ram or a file on a disk. However accessing devices usually require an initialization program, within C this is achieved by the fopen/fclose commands. The syntax of the fopen command is
 
    void main()
    {    
    FILE *name;
    name = fopen(device or file name , access);
 
    if (name == NULL ) 
    {
      printf("cannot open the file \n\r");
      exit(1);
    }
    }
 
The device or file name is usually machine dependent i.e.
 
    VMS    "dsk$usr:[en_staff.entjmc]file.ext"
    Unix    "dsk$usr:en_staff\entjmc\file.ext"
    Mac    "dskname:folder:folder:file";
    PC    "drive name:\directory\file.ext";
 
By default the current disk and directory are taken if not specified. The access describes the write/read privilege and type of data stored i.e. text or binary. Text is used to describe sequential data while binary is standard random access data
 
    "r"    Text file read only
    "w"    Create a new Text file write only
    "a"    Append to end of the text file
    "rb"    Binary file  read only
    "wb"    Binary file write only
    "ab"    Append to end of the binary file
    "r+"    Text file read and write 
    "w+"    Create a new text file for read and write
    "a+"    Append to end of the text file for read and write 
    "rb+"    Binary file read and write
    "wb+"    Create a binary file for read and write
    "ab+"    Append  to end of the binary file for read and write

For example to create a write access file called out.txt we use
 
    name = fopen("out.txt","w");
 
  i.e   file name  = out.txt
    access = create /write text file 
 
It is important to close all channels when finished; this is achieved by fclose i.e.
    
    fclose(name);


Related Discussions:- Stream input and output functions

Pseudo code, determining whether an integer is prime number or not

determining whether an integer is prime number or not

Program, superposition of waves

superposition of waves

Explain the for loop - computer programming, Explain the For Loop - Compute...

Explain the For Loop - Computer Programming? Similar to the while statement, for loop is an entry controlled loop and the code of the for loop will be executed itereatively. Th

Equation, My project is compiling but the equation entered is not working

My project is compiling but the equation entered is not working

What is default argument, Default argument: When the argument is missin...

Default argument: When the argument is missing then the function will read the default value of the missing argument.  To make use of default argument functionality the argu

Explain the parts of operators, Explain the parts of operators Assignm...

Explain the parts of operators Assignment Operators The equal (=) sign is used for assigning a value to another. The left hand side has to be a variable (lvalue, which exc

Explain polymorphism, Polymorphism C++ supports this idea - that differ...

Polymorphism C++ supports this idea - that different objects do "the right thing "- by function polymorphism and class polymorphism. Poly means many, while morph means form.

Static data members and static member function, Static Data Members: A ...

Static Data Members: A data member inside the class can construct as static data member.   There are few guidelines to be followed when declaring static data member.

Vogels approximation transportation problem, Vogels approximation transport...

Vogels approximation transportation problem in c language source code

Describe spaghetti programming, Describe spaghetti programming. - Spagh...

Describe spaghetti programming. - Spaghetti programming refers to codes which tend to get tangled and overlapped throughout the program. - It makes a program complex and ana

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd