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 6760261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:02:42+00:00 2026-05-26T14:02:42+00:00

The data structure of this code has to be how it has been written.

  • 0

The data structure of this code has to be how it has been written. I am having issues printing and adding to the memory locations. I think that I have the add function working properly but I am not sure. I don’t think I am moving in memory properly to print and add.

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

/********************************************
Creates more memory for size (strut * rec+1)
*********************************************/

employee *create(int record){
employee *new_employee = malloc(sizeof(employee) * (record+1));

return new_employee;    
 }

/********************************************
Copies the data from one structure to a new structure with 
size "structure" multipled by rec+1
 ***********************************************/
   employee *copy(employee *data, int record){
    employee *new_employee = create(record);

memcpy(new_employee, data, record * sizeof(employee));
/*  
int i;
    for(i = 0; i<record;i++){
        new_employee->first = data->first;
        new_employee->last = data->last;
        new_employee->start_date = data->start_date;
        new_employee->sal = data->sal;
        data++;
    }
*/  
    /********************
    Needs to free the old struct
    *********************/
    //deleteData(data, record);

return new_employee;
}
/********************************************
Function prints everything in the struct
*********************************************/
void printStruct(employee *data, int record){

employee *head = data;
employee *employeeDB = head;
int i;  
    for(i = 0; i<record; i++){
        printf("\nEntry: %d\n", i+1);           
        printf("The employee's name is %s %s\n", employeeDB->first, employeeDB->last);
        printf("The employee was hired on: %s\n", employeeDB->start_date);
        printf("The employee make $%f\n\n", employeeDB->sal);   
        employeeDB++;       
    }
}
/******************************************
Function frees the old data base
*******************************************/
void deleteData(employee *data, int record){
int i;
    for(i = 0; i<record; i++){
        free(data->first);
        free(data->last);
        free(data->start_date);
        data++;
    }
    free(data);
}
/******************************************
Adds an employee to the new structure
*******************************************/
employee *add(employee *data,char *fname, char *lname, char *date, float salary, int record){

fprintf(stderr, "\n\nEmployee data = %s for record # %d\n\n", data->first, record);
employee *head = create(record);
employee *employeeDB = head;
/*
employeeDB = copy(data, record);
fprintf(stderr, "Copied %d records\n", record);
*/

//
//      
//  
//  BUILD NEW EMPLOYEE
    employee * new_employee = malloc(sizeof(employee));
    new_employee->first = fname;
    new_employee->last = lname;
    new_employee->start_date = date;
    new_employee->sal = salary;

//  COPY EXISING DATA TO EMPLOYEEDB
    memmove(employeeDB,data,sizeof(employee));;

    fprintf(stderr, "Now the first record has first = %s\n", employeeDB->first);
    fprintf(stderr, "Now the first record(head) has first = %s\n", head->first);

    // MOVE HEAD
    employeeDB = employeeDB + record;

    memmove(employeeDB, new_employee, sizeof(employee));
    fprintf(stderr, "Now the first record has first = %s\n", employeeDB->first);
    fprintf(stderr, "Now the first record(head) has first = %s\n", head->first);

//
//
//
//
return head;
}




/**************************
Starts of the main function
***************************/

int main(void){
        //Keeps track of the number of records that are in the structure
int rec = 0;
        //Keeps the number of accesses to the structure. Even with the one entry the structure has not been accessed. 
int acc = 0;
        //Holds the input information for the menu
int input;
        //holds the information for inputing user first name
char fname[MAXSIZE];
        //holds the information for inputing user last name
char lname[MAXSIZE];
        //holds the information for for the startdate
char start[MAXSIZE];
        //holds the information for the salary;
float sal;


/*********************************
This next section adds an employee to the record
************************************/
//This creates the first entry to the dynamic structure.
employee *data_base = create(rec);
data_base->first = "FIRST";
data_base->last = "LAST";
data_base->start_date = "June-20th-2006";
data_base->sal = 55555.55;
//increase the number of records    
rec = rec+1;

/**********************************
/*
This starts the while loop that creates the menu for the user to choose from

**********************************/

while(1){
    printf("\nWELCOME TO myEMPLOYEE DATABASE\n");
    printf("\n------------------\n");
    printf("\nMENU");
    printf("\n1. Print All Records\n");
    printf("2. Print Number of Records\n");
    printf("3. Print Size of database\n");
    printf("4. Add an Employee\n");
    printf("5. Delete all Employee\n");
    printf("6. Print number of accesses to database\n");    
    printf("7. EXIT\n");
    printf("\nENTER SELECTION:  ");



    /* This scanf functions scans for the appropiate input, if the input is
     not one of the selection items the program exits*/

    scanf("%d", &input);

    switch (input) {
        case 1:         
            printStruct(data_base, rec);
            acc = acc + 1;
            break;
        case 2:
            printf("The number of records are %d\n", rec);
            acc = acc + 1;
            break;
        case 3:
            printf("The size of the data base is %d\n", sizeof(employee) * rec);
            acc = acc + 1;              
            break;
        case 4:

            printf("\nPlease enter the employee's first name:");
            scanf("%s", fname);
            printf("\nPlease enter the employee's last name:");
            scanf("%s", lname);
            printf("\nPlease enter the employee's start date (Month-Day-Year):");
            scanf("%s", start);
            printf("\nPlease enther the employee's salaray:");
            scanf("%f", &sal);
            acc = acc + 1;              

            break;
        case 5:

            break;
        case 6:
            printf("The number of accesses to the data is: %d", acc);
            break;
        case 7:
            printf("The program has exited");
            return 1;

        default:
            // If a wrong selection is entered it will display this message. 
            printf("Please enter a selection 1-7"); 

    }   
}

}


/*

Header file for pointer.c



*/
#include <string.h>
#define MAXSIZE 255;
typedef struct info {
char *first;
char *last;
char *start_date;
float sal;
}employee; 



 employee *create(int record);
 employee *copy(employee *data, int record);
 void printStruct(employee *data, int record);
 void deleteData(employee *data, int record);
 employee *add(employee *data,char *fname, char *lname, char *date, float salary, int record);
  • 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-26T14:02:42+00:00Added an answer on May 26, 2026 at 2:02 pm

    Remove the ; from the end of #define MAXSIZE 255;. Wherever you have MAXSIZE it’ll be replaced by 255;, and therefore char fname[255;]; is obviously invalid.

    #define MAXSIZE 255

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

Sidebar

Related Questions

I have a data structure that represents C# code like this: class Namespace: string
This question has been answered. The problem was that myEventMoveTrainManaul() was being called from
I have two data structure classes (this is a simplified version of my code)
I got this formula from a data structure book in the bubble sort algorithm.
This question is about a data structure I thought of. It is a dynamic
Here is my data structure alt text http://luvboy.co.cc/images/db.JPG when i try this sql select
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
I have a set of data that is structured like this: ItemA.GroupA ItemB.GroupA ItemC.GroupB
EDIT following resolution, this has been substantially edited to dump irrelevant detail and explain
i have some html files as part of a regular website that has been

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.