Open file , Take input from KEYBOARD, write in the file, Display the content of the file and close the file.
/* User Progam , to be executed in the user space */
/* openfile3.c */
// Author : (Raj)
#include<stdio.h>
#include<fcntl.h>
static int count;
int main()
{
int fd1,i,len;
char buffwr[100],buffr[100];
fd1=open("test1.txt",O_CREAT|O_RDWR,0777); // Opening of file in read and write mode.
if(fd1<0)
{
printf("File 1 cannot be open. \n");
return 0;
}
else
{
printf("File Discripter value of the File 1 is : %d\n",fd1);
printf("Enter the data to write into the file....\n");
i=read(0,buffwr,100);
buffwr[i]='\0';
len=strlen(buffwr);
write(fd1,buffwr,len);
lseek(fd1,0,0);
i=read(fd1,buffr,100);
buffr[i]='\0';
printf("******************************************************\n");
printf("Entered the data : %s\n",buffr);
}
close(fd1);
return 0;
}
0 comments:
Post a Comment