explain plz 2.26 (only) 2.23 How are iOS and Android similar? How are they diffe
ID: 3886077 • Letter: E
Question
explain plz 2.26 (only)
Explanation / Answer
The Answer For your Qurestion is given below
Explanation:
The Input file will be containing the string Welcome and This Input string Welcome will be copied to the buffer in our code and our aim is achieved by using open and read POSIX's API and for copying the data we used buffer
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define BLOCK_SIZE 4096
int main()
{
int sds=-1; //variable declaration
ssize_t read_bytes=-1;
int i=0; //variable declaration
char buffers[50]; //variable declaration
sds=open("./file-to-buffers.txt",O_RDONLY);
if(-1 == sds)
{
perror("Open Failed");
return 1;
}
while((read_bytes=read(sds,buffers,BLOCK_SIZE))>0)
{
printf("the no of read_bytes=%d ",read_bytes);
}
while(buffers[i]!='')
{
printf("buffers[%d]=%d ",i,buffers[i]); //Testing forcharacters read from the file to buffer.The file contains "Welcome"
i++;
//buffers[5]= -How?
}
//buffers[6]=``-How?
close(sds);
return 0;
}
Sample Output:
the no of read_bytes=7
buffers[0]=w
buffers[1]=e
buffers[2]=l
buffers[3]=c
buffers[4]=o
buffers[5]=m
buffers[6]=e
buffers[7]=
Hope This HElps, if you have any doubts please comment i will get back to you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.