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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:09:58+00:00 2026-06-18T14:09:58+00:00

We are learning C++ at the moment and I don’t think this code requires

  • 0

We are learning C++ at the moment and I don’t think this code requires us to use pointers yet.

So, for suggestion to the answer, please let me know if it can be done without pointer or not.

Question: How to compare an array of char so that you can sort them in ascend order?

Details:

Goal: Sort the name in ascending order as they are inserted

What we have here:

char name[1024]; // which is a part of a Struct 

The insertion works. Once it is inserted. I am trying to rearrange the order so that the names are in

ascending order.

I have:

if (RecordCollection[i].name > RecordCollection[i+1].name) // for comparing 

I think this might be where the problem is? Can C++ compare like that? Like, comparing John with Amy with

that one line?

After that if statement, I am using swapping the elements so they are in correct order. For example: 
If John[0] the current name is > than Amy[1], then copy John to a temporary. 
Then copy Amy to index[0]. 
Then copy John in temporary to index[1].

While typing this question, I think I need to compare the char one by one… J with A, if not the same then

sort. If same, move onto next char until it finds something different to sort. But then I don’t know how to

get the char 1 by 1.

  • 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-18T14:09:59+00:00Added an answer on June 18, 2026 at 2:09 pm

    If you are using strings, see strcmp.

    man strcmp

    A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; a value less than zero indicates the opposite.

    To sort your array, you can also use qsort from the standard C library.

    #include <string.h>
    
    int
    cmp (const void *p, const void *q)
    {
      return strcmp (p, q);
    }
    
    qsort (RecordName, nelems, 1024, cmp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am doing this as a learning moment and I'm not afraid to
I am learning perl at this moment and have a short script in which
I'm learning JavaScript at the moment and I don't quite understand when to write
I'm learning how to dynamically load DLL's but what I don't understand is this
I know this probably isn't as easy to answer when you don't have all
I'm learning how to use Coolite at the moment. I'm trying to use the
i am newbee in yii and i am learning at this moment ... I
I'm learning javascript at the moment and the code below isn't producing the results
Im learning to code in x86 assembly (32-bit at the moment) and I'm struggling
i am learning java at this moment and i've read somewhere that i can

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.