Follow me

Saturday 18 January 2020

c file handling notes 01 scabhopal


file handling in a program is mechanism using which a pro can save all the data (values stored in variable, array, structure etc) in secondary memory of our memory so that we can retrieve it in future.

in simple word we can say that the file handling provides data persistence

real world of file handling- there are many app /programs which make use of file handling internally
1. chatting app like WhatsApp
2. call logs in a mobile phone
3. pc games
4. mobiles phone book etc.

how c language support file handling -

File - predefined structure
Declaration - stdio.h
use- we create its "pointer"
initialize- predefined function.

Steps req. for writing data in a file-

1. decl. a file pointer = FILE *fp;

2. connect the file pointer with a file | fp = fopen("d:\\data.txt","w");

3. write the data in in file | fputc('H',fp);

4. save & close | fclose()

que.1
Write a program to create a file called message.text in your d:\.
now ask the user to input some text and write the given text in the file.

que. 2
Write a program to open the file created by the previous code. Read it and display it's
contents on the screen.

que. 3
Assume, there is a file in your d:\ called message.txt write a prog to create another file called message2.txt and copy the contents of the file message.txt in message2.txt.
==============================================================
ASSIGNMENT: -
==============================================================
que. 4
Assume, there is a file in your d:\ called message.txt write a program to create another file called message2.txt and copy the contents of the file message.txt in message2.txt by reversing their cases(uppercase to lowercase or lower case to uppercase).










No comments: