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

  • Home
  • SEARCH
  • 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 7802265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:12:41+00:00 2026-06-02T01:12:41+00:00

I am writing a program that accepts a file with database entries in it.

  • 0

I am writing a program that accepts a file with database entries in it. The entries are all in the same format, with the data in the same order. The first number in the file is the number of entries. Then the data looks like this:
LastName FirstName StudentID age year GPA expectedGraduationDate

Ex:
Doe John 12345678 23 freshman 4.0 2013

My issue is with the year value. We are supposed to declare it as type ‘class’, which is supposed to be enum class{freshman, sophomore, junior, senior, grad};

I have a header file with the following declaration:

typedef enum {firstYear, sophomore, junior, senior, grad} class;

Then my main file:

#include <stdio.h>
#include <stdlib.h>
#include "class.h"

int main(int argc, char *argv[]){

typedef struct{
        int DBrecordID;         //ID for each entry, range 0-319
        char *last;             //student last name
        char *first;            //student first name
        char studentID[8];      //student ID
        int age;                //student age
        class year;             //year in school
        float gpa;              //GPA
        int expGradYear;        //expected graduation year
}DBrecord;
int numEntries;
DBrecord **record;
char buffer[80];
FILE *fpt;
int c, i;
int j = 0;

//check for invalid file arguments
if(argc != 2){
        printf("Number of arguments is invalid\n");
        exit(1);
}

//error if unable to open file
if((fpt = fopen(argv[1], "r")) == NULL){
        printf("Error: Couldn't open file.\n");
        exit(1);
}

//set file pointer to read passed file
fpt = fopen(argv[1], "r");

//scan first int in file and assign to numEntries
//fscanf(fpt, "%d", &numEntries);

//allocate memory for structures, each is 36 bytes
*record = malloc (sizeof (DBrecord) * numEntries);

//loop through each DB entry
do{
        for(i=0; i<numEntries; i++){
                numEntries = record[i]->DBrecordID;
                do{
                        c=fgetc(fpt);
                        buffer[j++] = c;
                }while(c != ' ');
                        strcpy(record[i]->last, buffer);
                        j=0;
                do{
                        c=fgetc(fpt);
                        buffer[j++] = c;
                }while(c != ' ');
                        strcpy(record[i]->first, buffer);
                        j=0;
                do{
                        c=fgetc(fpt);   
                        buffer[j++] = c;
                }while(c != ' ');
                        strcpy(record[i]->studentID, buffer);
                        j=0;
                do{
                        c=fgetc(fpt);
                        memcpy(c, buffer[j++], 1);
               }while(c != ' ');
                        memcpy(buffer, record[i]->year, 4);
                        j=0;
                do{
                        c=fgetc(fpt);
                        buffer[j++] = c;
                }while(c != ' ');
                        memcpy(buffer, record[i]->gpa, 4);
                        j=0;
                do{  
                        c=fgetc(fpt);
                        buffer[j++] = c;
                }while(c != ' ' || c != '\n');
                        memcpy(buffer, record[i]->expGradYear, 4);
                        j=0;
         }
}while(c != EOF);

return 0;
}

*Updated errors

main.c:75: warning: passing arg 1 of `memcpy’ makes pointer from integer without a cast

main.c:75: warning: passing arg 2 of `memcpy’ makes pointer from integer without a cast

main.c:77: incompatible type for argument 2 of `memcpy’

main.c:83: incompatible type for argument 2 of `memcpy’

main.c:89: warning: passing arg 2 of `memcpy’ makes pointer from integer without a cast

main.c:94: parse error before “DBrecord”

So I’m assuming I can’t do what I’m trying to do with memcpy, or I’m just doing it wrong. Suggestions?

  • 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-06-02T01:12:43+00:00Added an answer on June 2, 2026 at 1:12 am

    There quite a few errors in the program but for a start

    1) record should be of type DBrecord* not DBrecord**

    2) strcpy takes destination as the first argument so this wouldn’t work
    strcpy(buffer, record[i]->last);

    3) you also need to allocate memory for record[i]->last

    4) strcpy is used to copy strings so if you wan’t to store to float or int i.e. gpa etc you need to use memcpy also the value from buffer should be converted using strol strod

    also would recommend to get hold of this book K&R it would be really helpful overtime

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

Sidebar

Related Questions

I'm writing a C program that accepts input one line at a time from
I am writing a program in c++ that accepts a filename as an argument
I'm writing a program in Python that accepts command line arguments. I am parsing
I'm writing an autograder web application that accepts a program from the user as
Im writing a little python program that goes through an XML file and does
I'm beginner to c++ and writing a program that accepts user choices and acts
I' writing a program that stores opening hours for a store in a database
I am writing a Java program that inputs a test file, performs some modifications
Im writing a program that should read input via stdin, so I have the
I'm writing a program that sends an email out at a client's specific local

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.