Computer Science, asked by kiran5830, 1 year ago

flowchart to create a file and write data elements into a file and read data from a file c program.​please fill the spaces please

Attachments:

Answers

Answered by royalsachin16nov2004
0

size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)

ptr - This is pointer to array of elements to be written

size - This is the size in bytes of each element to be written

nmemb - This is the number of elements, each one with a size of size bytes

stream - This is the pointer to a FILE object that specifies an output stream

filter_none

edit

play_arrow

brightness_4

// C program for writing

// struct to file

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

// a struct to read and write

struct person

{

int id;

char fname[20];

char lname[20];

};

int main ()

{

FILE *outfile;

// open file for writing

outfile = fopen ("person.dat", "w");

if (outfile == NULL)

{

fprintf(stderr, "\nError opend file\n");

exit (1);

}

struct person input1 = {1, "rohan", "sharma"};

struct person input2 = {2, "mahendra", "dhoni"};

// write struct to file

fwrite (&input1, sizeof(struct person), 1, outfile);

fwrite (&input2, sizeof(struct person), 1, outfile);

if(fwrite != 0)

printf("contents to file written successfully !\n");

else

printf("error writing file !\n");

// close file

fclose (outfile);

return 0;

}

Similar questions