Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6675119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:48:52+00:00 2026-05-26T03:48:52+00:00

Below is a quick program I created, The program is suppose to keep a

  • 0

Below is a quick program I created, The program is suppose to keep a trace of blood donors.

#include <stdio.h>
#include <conio.h>

struct donors
{
 char name[20];
 char address[40];
 int age;
 int blood_type;
};

void main()
{
  int ask,i=0;
  struct donors d;

  FILE *fp;
  fp = fopen("Blood_Donors.txt","r");


  clrscr();

  if(fp==NULL)
  {
    printf("Error: Unable to open file.");
    printf("\nDo you want to create a new file ? (Y = 1 / N = 0) : ");
    scanf("%d",&ask);
    if(ask==1)
    {
      fp = fopen("Blood_Donors.txt","w");
    }

    if(fp!=NULL)
    {
      printf("\nFile Created\n");
    }
    else
    {
     if(ask==1)
     {
      printf("\nError: Unable to create file");
      printf("\nPress any key to exit the program");
      getch();
      exit(1);
      }
      else
      {
       printf("\nFile not created \nPress any key to exit the program");
       getch();
       exit(1);
      }
    }
  }
  else
  {
   fp = fopen("Blood_Donors.txt","a");
   printf("Do you want to enter a record ? (Y = 1 / N = 0) : ");
   scanf("%d",&ask);
  }

  while(ask==1)
  {
    i=i+1;
    fflush(stdin);
    printf("Enter name (Maximum 20 characters) : ");
    gets(d.name);

    fflush(stdin);
    printf("Enter address (Maximum 40 characters) : ");
    gets(d.address);

    fflush(stdin);
    printf("Enter age (Maximum 2 characters) : ");
    scanf("%d",&d.age);

    fflush(stdin);
    printf("Enter Blood Type \n(A- = 1, A+ = 2, B- = 3, B+ = 4, AB- = 5, AB+ = 6, O- = 7, O+ = 8) : ");
    scanf("%d",&d.blood_type);

    fprintf(fp,"<donor %d>\nName: %s\nAddress: %s\nAge: %d\nType: %d\n\n",i, d.name, d.address, d.age, d.blood_type);
    fflush(stdin);

    printf("\n\nDo you want to enter another record ? (Y = 1 / N = 0) : ");
    scanf("%d",&ask);
   }

  fclose(fp);
  getch();
}

a) how to increase the value of i appropriately ? where i holds the number of the previous donor.
b) how to print the details of all donors below age 30 and whose name starts with ‘s’ ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:48:52+00:00Added an answer on May 26, 2026 at 3:48 am

    a)Since you are saving to a file, why not declare the first line of the file as a single number i representing the number of donors so far, followed by i lines of donors?

    b)you might want to lookup xml’s

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my current char* to hex string function. I wrote it as an
Attached is a quick program written under interview conditions that is designed to flatten
Here is a quick and dirty GLUT based C++ program for windows that draws
please refer to my quick diagram attached below. what i'm trying to do is
Quick question if I may: I am just curious about the following (see below)
A quick question if I may, can anyone explain what I am missing below,
Just a quick memory management question if I may ... Is the code below
Please have a quick look below, what is wrong here? $tmp_img_path=../temp_images/; $name_image1=mypicture.jpeg; $new_img_path=../images/; rename($temp_img_path.$name_image1,
I've been using the below code fine for a quick and efficient function of
Given I have the below clients hash, is there a quick ruby way (without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.