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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:42:17+00:00 2026-06-15T15:42:17+00:00

I am trying to bubble sort the LastName property (under a struct StudentRecord, hence

  • 0

I am trying to bubble sort the LastName property (under a struct StudentRecord, hence the names) of an array using bubble sort. But I am having trouble doing so.

I am receiving the error (I’m using MinGW to compile):

Invalid array assignment

Here is my code:

void option2 (StudentRecord student[], int n)
{
   int pass = 1;
   bool done = false;
   StudentRecord temp;
   while (!done && pass <= n-1)
   {
      done = true;
      for (int i = n-1; i >= pass; i--)
      {
         if (student[i].lastName < student[i-1].lastName)
         {
            temp.lastName = student[i].lastName;
            student[i].lastName = student[i-1].lastName;
            student[i-1].lastName = temp.lastName;
            done = false;
         }
      }
      pass++;
   }
}
  • 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-15T15:42:18+00:00Added an answer on June 15, 2026 at 3:42 pm

    It looks like lastName is an array of characters.

    You can’t assign entire arrays to each other; you need to use strcpy() (#include <cstring>) to copy one to the other. Additionally, using < with character arrays will cause the memory addresses of the first elements in each array to be compared, not the entire string of characters; use strcmp for this (which returns < 0 iff the first parameter is lexicographically < the second parameter).

    Note you can (and probably should) use std::string instead (#include <string>), which will automatically provide copying, comparison, and dynamic growth for you transparently.

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

Sidebar

Related Questions

I am trying to sort an array of integers in MIPS using bubble sort
I have been trying to implement Bubble Sort using simple integer array in java.
I'm trying to make bubble sort using Cocoa classes, but I've found some problems.
I'm trying to bubble sort a character array in alphabetic order. My code is
I'm trying to use the bubble sort method to sort an array of only
I am trying to sort a singly linked list using bubble sort. If there
I am trying to write my own bubble sort algorithm as an exercise. I
I'm new to pl/sql ! I'm trying to sort a table of records, using
I am trying to create a bubble sort on a doubly linked linked list
I am trying to write a simple bubble sort in Common Lisp (also works

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.