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

Facebook auto like system, I want a PROGRAM - Facebook auto like system to ...

I want a PROGRAM - Facebook auto like system to increase fans to different fanpage It has in a program that take Facebook mails and passwords from a excel file (.xlsx) for examp

C++, #include long BixFunction(int x, int y = 5, float z = 5) { return...

#include long BixFunction(int x, int y = 5, float z = 5) { return(++x * ++y + (int)++z); } int main() { cout return 0; }

C program to find the even words in the string, C Program to FIND THE EVEN ...

C Program to FIND THE EVEN WORDS IN THE STRING #include conio.h> #include stdio.h> void main() {           char a[50],temp;           int i=0,k=0,l[25],c=0,r=0;

Is there anything you can do in c++ which you cannot do in c, A: No. There ...

A: No. There is nothing you can do in C++ which you cannot do in C. In spite of everything

Write a recursive function with cylinders, I need to make a fractal trees i...

I need to make a fractal trees in OpenGL C++ . The method used is to write a recursive function with cylinders of different sizes and angles to create the tree trunk and branches.

Define storage classes of c program - computer programming, Define Storage ...

Define Storage Classes of c program - computer programming? Each variable and function in C language has two attributes that are type and storage class. If storage class of a v

Write a program to define a matrix, Write a program to define a matrix: ...

Write a program to define a matrix: 1. Write a function that takes an integer and calculates and returns the factorial of the integer. The Factorial of a number "n" is compute

Explain the type conversion in expressions in c language, Explain The Type ...

Explain The Type Conversion in Expressions in c language? When variables and constants of different types are used in an expression they are all converted to same type. The com

AREAUNDERCURVE, Write a program to find the area under the curve y = f(x) b...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw

Define one's complement operator, Define One's Complement Operator? The...

Define One's Complement Operator? The one's complement operator, occasionally called the "bitwise NOT" or "bitwise complement" operator produces the bitwise one's complement of

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