FILE - struct customer { int id; char name[30]; }; } void...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* FILE *stream; int i = 100; char c = 'C'; float f = 1.234; /* open a file for update stream = fopen("DUMMY.FIL", "w+"); /* write some data to the file fprintf(stream, "%d %c %f", i, c, f); /* close the file fclose(stream); */ /* / if ((stream = fopen("DUMMY.FIL", "w+")) == NULL) { fprintf(stderr, "Cannot open output file.\n"); return 1; } /* write some data to the file fwrite(msg, strlen(msg)+1, 1, stream); f /* seek to the beginning of the file fseek(stream, SEEK_SET, 0); f /* read the data and display it fread(buf, strlen(msg)+1, 1, stream); printf("%s\n", buf); */ * #include <stdio.h> #
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: struct customer { int id; char name[30]; }; } void main() { FILE *stream; struct customer s,q; clrscr(); printf("Enter Customer ID:"); scanf("%d",&s.id); printf("Enter Customer NAME:"); scanf("%s",s.name); stream = fopen("customer.txt", "w+"); /* open file TEST.$$$ */ fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */ fseek(stream, SEEK_SET, 0); // fprintf(stream, "\nId:%d \nName:%s ",s.id,s.name); / fread(&q, sizeof(s), 1, stream); printf("\nID:%d \nNAME:%s",q.id,q.name); fclose(stream); /* close file */ getch(); }...
View Full Document

This note was uploaded on 10/25/2010 for the course CMPN SEM3 taught by Professor Thakur during the Fall '07 term at University of Mumbai.

Page1 / 2

FILE - struct customer { int id; char name[30]; }; } void...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online