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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:10:03+00:00 2026-05-18T03:10:03+00:00

I’m a new code monkey in training, and I’m currently having issues working with

  • 0

I’m a new code monkey in training, and I’m currently having issues working with arrays and structs.
Currently I have a main file where I have a an Array of Records declared. I pass that array to an external function, where a quick sort is performed on the with of the fields in the record. Mainly the first name. I’m having an issues where I copy elements in the array of records, to a temporary array for the sorting algorith. I know that c++ does have a qsort function built in, but for what I’m working on right now, I need to have the algoritm written out the way it is. I was able to get this to work using only any array.

I’m getting the following error when trying to compile with the make file.

make
g++    -c -o main2.o main2.cpp
g++ -c externArray2.cpp -o externArray2.o
externArray2.cpp: In function ‘void copytemp(EmployeeRecord*, EmployeeRecord*, int, int)’:
externArray2.cpp:52: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:53: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:54: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:55: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:56: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:57: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:58: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:59: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
externArray2.cpp:60: error: cannot convert ‘float’ to ‘void*’ for argument ‘1’ to ‘void* memcpy(void*, const void*, size_t)’
make: *** [externArray2.o] Error 1

Make File

test1:  main.o ExternArray.o
        g++ main.o ExternArray.o -o test1

externArray.o: ExternArray.cpp
        g++ -c ExternArray.cpp -o ExternArray.o

main.o: main.cpp
        g++ -c main.cpp -o main.o

Header.h

#ifndef _INCL_GUARD
#define _INCL_GUARD
const int maxEmployee =10;
const int NAMES = 5;
const int LENGTH = 15;


typedef struct EmployeeRecord
{
char first[10];
char last[10];
float reghours;
float ovrhours;
float pay;
float gross;
float defer;
float state;
float fed;
float ssi;
float net;
} EmployeeRecord;
#endif

main.cpp

#include <iostream>
#include <cstring>
using namespace std;
#include "./Header2.h"

void showArray(EmployeeRecord employees[], int, const char*);  //Function Prototype 3.1

extern void qsortArray(EmployeeRecord employees[], int, int);     //Funvtion Prototype      3.2

int main(void)
{
    EmployeeRecord myEmployee[maxEmployee];
    strcpy(myEmployee[0].first,"John");
    strcpy(myEmployee[0].last,"Doe");
    strcpy(myEmployee[1].first,"Ed");
    strcpy(myEmployee[1].last, "Whittle");
    strcpy(myEmployee[2].first, "Louise");
    strcpy(myEmployee[2].last, "Marion");
    strcpy(myEmployee[3].first,"Paula");
    strcpy(myEmployee[3].last, "Prentiss");
    strcpy(myEmployee[4].first, "Carl");
    strcpy(myEmployee[4].last, "Davidson");


    showArray(myEmployee, NAMES, "Before Sort");
    qsortArray(myEmployee, 0, 4 );
    showArray(myEmployee, NAMES, "After Sort");

return 0;               
}



void showArray(EmployeeRecord employees[], int emp, const char *message)
{
cout << message << endl;
for (int test = 0; test < emp; test++)
    {
    cout << "First Name: " << employees[test].first << endl;
    cout << "Last Name: " << employees[test].last << endl;

    }
}

ExternArray.cpp

#include <cstring>
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
#include "./Header2.h"

void qsortArray(EmployeeRecord employees[], int, int);     //Funvtion Prototype         3.2

void copytemp(EmployeeRecord tmpEmp[], EmployeeRecord emp[], int, int);

void qsortArray(EmployeeRecord employees[], int start, int finish)
{

int left=start,
    right=finish;
char  pivot[15];
strcpy(pivot, employees[(start+finish)/2].first);
  while (left < right) {
  cout << pivot << " pivot " << endl;
  cout << "outer loop" << endl;
    // find left candidate
    while (strcmp(employees[left].first,pivot) <0) left++; 
    // find right candidate 
    cout << "First Inner Loop" << endl;
    while (strcmp(employees[right].first,pivot) > 0 )right--; 
    cout << "Inner Loop" << endl;
    if (left <= right) 
        {
        EmployeeRecord tmpEmployee[1];
        cout << "Create new struct" << endl;
        copytemp(tmpEmployee, employees, 0, left);
        cout << "copy to temp" << endl;
        copytemp(tmpEmployee, employees, 1, right);
        copytemp(employees, tmpEmployee, left, 1);
        copytemp(employees, tmpEmployee, right, 0);

        left++;
        right--;
        cout << "All copy done" <<endl;
        } 
  } // while left < right
  cout << "Back out of outer Loop" << endl;
  if (start < right) qsortArray(employees,start,right);
  if (left < finish) qsortArray(employees,left,finish);
}

void copytemp(EmployeeRecord tmpEmp[], EmployeeRecord emp[], int first, int secound)
{
memcpy(tmpEmp[first].first, emp[secound].first, sizeof(emp[secound].first));
memcpy(tmpEmp[first].last, emp[secound].last, sizeof(emp[secound].last));
memcpy(tmpEmp[first].reghours, emp[secound].reghours, sizeof(emp[secound].reghours));
memcpy(tmpEmp[first].ovrhours, emp[secound].ovrhours, sizeof(emp[secound].ovrhours));
memcpy(tmpEmp[first].pay, emp[secound].pay, sizeof(emp[secound].pay));
memcpy(tmpEmp[first].gross, emp[secound].gross, sizeof(emp[secound].gross));
memcpy(tmpEmp[first].defer, emp[secound].defer, sizeof(emp[secound].defer));
memcpy(tmpEmp[first].state, emp[secound].state, sizeof(emp[secound].state));
memcpy(tmpEmp[first].fed, emp[secound].fed, sizeof(emp[secound].fed));
memcpy(tmpEmp[first].ssi, emp[secound].ssi, sizeof(emp[secound].ssi));
memcpy(tmpEmp[first].net, emp[secound].net, sizeof(emp[secound].net));
}
  • 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-18T03:10:03+00:00Added an answer on May 18, 2026 at 3:10 am

    In C you can copy an entire struct with a plain assignment

    tmpElm[first] = emp[secound];
    

    This is only problematic if the struct contains members which are pointers, which is not your case.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.