Question

Write statements to accomplish each of the following. Assume the structure
struct person
{
char lastName [10];
char City [20];
int Age;
};
has been defined and that the file is already open for writing.
i. Initialize the file ”personaldata.dat” so that there are 100 records with
lastName=””, City=” ” and Age = 0.
ii. Input 10 last names. first names and ages and write them to the file

19 Mar 2023
Answer :
Word Count : 299

i. To initialize the file "personaldata.dat" with 100 records with empty last name, city name and age equal to 0, we can use the following code:

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct person {
    char lastName[10];
    char City[20];
    int Age;
};

int main() {
    FILE *fp;
    struct person p = {"", "", 0};
    int i;

    fp = fopen("personaldata.dat", "wb"); // open the file for writing in binary mode

    for (i = 0; i < 100; i++) {
        fwrite(&p, sizeof(struct person), 1, fp);

_______ ____ _____ __________ ______ _________ ____ ___ ____ __________.
____ ____ __________ __________ __________ ______ _______.
___ _____ _______ _______ ________ __________ ______ __________ __________ ________.
__________ ______ ______ ________ ______ ___ _____.
_____ _________ ____ ______ ___.
__________ ________ _________ ___ _____ ___ ________ _____ _____.
____ _____ _________ ______ ___ ________ ________ ___.
_________ ___ _________ __________ ______ ___ __________.
_________ ___ __________ ______ _________ ________.
_______ ___ ____ ________ ____ ______ ___.
____ _________ __________ __________ ___ ____ ________ ______ _______.
___ ___ ____ _________ _______.
______ _____ ___ ______ ______ ______ __________.
____ _______ _________ __________ ______ ___.
__________ _________ ________ ______ ___.
___ _________ _____ _______ ________ ___ _________ ________ _______ ___ ____.
____ ______ __________ ________ ________ ___ _________ _______ _____ ___ _____.
__________ __________ ____ _____ ____ ______ _________.
________ ________ ___ _________ _________ ________ ___ _____.
____ __________ ______ ___ ____ _______ ______.
_______ ________ _____ _____ ____ ________ ____ _____ __________ _______ ______ _____.
_____ _________ ______ _________ _____ __________ _________ ____.
_________ __________ __________ __________ ________ _____ _______.
_________ ______ ___ ___ ______ ________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MMT 1 2023 - Write statements to accomplish each of the following. Assume the struc | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→