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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:51:41+00:00 2026-06-09T07:51:41+00:00

I am trying to use a sorting function for grade, which will sort name

  • 0

I am trying to use a sorting function for grade, which will sort “name surname midterm1”, but I cannot figure how to assign name and surname strings to a temp array. Any ideas?

void student_swap(struct student *x){
    int z,y,temp;
    char temp2[15];
    for(z=0; z<10; z++){
        for(y=0; y<9; y++){
            if(x[y].mid1>x[y+1].mid1){
                temp = x[y+1].mid1;
                x[y+1].mid1 = x[y].mid1;
                x[y].mid1 = temp;

                strcpy (temp2,x[y+1].name);
                strcpy (x[y+1].name,x[y].name);
                strcpy (x[y+1].name,temp2);
                strcpy (temp2,x[y+1].surname);
                strcpy (x[y+1].surname,x[y].surname);
                strcpy (x[y+1].surname,temp2);

            } // if
        } // for
    } // for
} //student_swap

Sorting int values works fine but strcpy does nothing.
this is my out put code

for (i=9;i>=0;i--){
    ;
    printf ("%s %s %d\n",x[i].name,x[i].surname,x[i].mid1);
}
printf ("\n");

       student_swap(x);

    for (i=9;i>=0;i--){
    ;
    printf ("%s %s %d\n",x[i].name,x[i].surname,x[i].mid1);
}

and this is my output

murat hot 73
mehmet umur 72
idil saracoglu 55
ecem bektas 75
sevde pir 70
asli devecioglu 65
can akkurt 45
levent dogan 60
anil erdiz 30
ali durmus 40

murat hot 75
mehmet umur 73
idil saracoglu 72
ecem bektas 70
sevde pir 65
asli devecioglu 60
can akkurt 55
levent dogan 45
anil erdiz 40
ali durmus 30
  • 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-09T07:51:42+00:00Added an answer on June 9, 2026 at 7:51 am

    Shouldn’t it be:

        strcpy (temp2,x[y+1].name);
        strcpy (x[y+1].name,x[y].name);
        strcpy (x[y].name,temp2);    // <-- note the index used
    

    ?

    And likewise for the surname.

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

Sidebar

Related Questions

I am trying to use MPI to sort digits, after sorting by the different
So I'm trying to use a sorting function (similar to bubble) and pass into
I'm trying to implement some STL-style sorting algorithms. The prototype for std::sort looks something
I am currently trying to make a special sort function for a Magento category
I'm trying to sort a vector of objects using a predicate function and I'm
In this JSFiddle http://jsfiddle.net/littlesandra88/mzPxN/ am I trying to use the tablesorter plugin to sort
Possible Duplicate: Python not sorting unicode properly. Strcoll doesn't help. I'm trying to sort
I have a sorting comparator which I need to use in a few different
I trying to sort some data to use sortedArrayUsingDescriptors: method in an NSArray class.
I'm trying to implement a array based Heap Sort, its sorting the first few

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.