Posts

Showing posts with the label File handling

C program source code to create file in file handling

C program source code to create file in file handling Write a C program  to create file in file handling C Program source code #include<stdio.h> #include<conio.h> int main() { FILE *fptr; fptr=fopen("Test.txt","w"); if(fptr==NULL) { printf("\nFile can not be opened"); } else { printf("File is succesfully created"); } fputs("welcome to c programming",fptr); fclose(fptr); getch(); return 0; } You can Browse related article below for more information and program code related to recursive function call  Does above is helpful , Post you views in comment DO NOT MISS OTHER C PROGRAMMING TUTORIAL * indicates required Email Address *

File handling in c program - I

Image
Filehandling in c program - I WRITING TO AND READING FROM A FILE #include main() { FILE *f1; char c; printf("Data Input\n\n"); /* Open the file INPUT */ f1 = fopen("INPUT", "w"); /* Get a character from keyboard */ while((c=getchar()) != EOF) /* Write a character to INPUT */ putc(c,f1); /* Close the file INPUT */ fclose(f1); printf("\nData Output\n\n"); ...

Opening a file in c

Image
Opening a file in c A file must be opened before any I/O operation can be performed on that file . The process of establishing a connection between the program and the file is called opening the file A structure named FILE Is defined in the file stdio.h that contains all information about the file like name , status , buffer size , current position , end of file status etc . All these details are hidden from the programmer and the operating system takes care of all these things. typedef struct { …………. …………… } FILE; A file pointer is a pointer to a structure of type FILE . Whenever a file is opened , a structure of type FILE is associated with it , and a file pointer that points to this structure identifies this file . The function fopen() is used to open a file Declaration FILE *fopen (const char *filename , const char *mode); fopen() function takes two string as arguments , the first one is the name of the file to be opened and the second one is the mod...

Difference between text file and binary file

Image
Difference between text file and binary file There are two kinds of storing data in file text format and binary format .  In text file data are stored as line of characters with each line terminated by a new line character (‘\n’). In binary format data is stored on the disk in the same way as it is represented in the computer memory . Unix system does not make any distinction between text file and binary file.  Text file are in human readable form and they can be created and read using any text editor , while binary file are not in human readable form and they can be created and read only by specific program written for them . The binary data stored in file can not be read using text editor. The hexadecimal value of 1679 is 0x068f , so in binary format it is represented by two bytes 0x06 and 0x8f . In a text file 1679 is represented by the bytes 0x31 , 0x36 , 0x37 ,0x39 ( ASCII values) . NOTE ASCII value for 1 is 31 and for 9 is 39.  Both text ...