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

The Archive Base Latest Questions

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

For this assignment I had to create my own string class. I initially wrote

  • 0

For this assignment I had to create my own string class. I initially wrote the compareto method to compare two string but return whichever is overall larger. What I want to do is compare and return which one is alphabetically larger i.e. comparing two strings, for example: smith and htims. With the way I designed the compareto method is that the result will be that they are equal. What I want to do is tell me which one comes first alphabetically, so for my example htims would come first. I understand how to do this in Java or even in C with using the <string.h> library, I am just confused as to how to do this myself.

EDIT: I just wanted to note that I am not looking for code answer, rather a nudge in the how I should write the code.

int compareto(void * S1, void * S2){
    String s1 = (String S1);
    String s2 = (String S2);
    int i, cs1 = 0, cs2 = 0; //cs1 is count of s1, cs2 is count of s2

    while(s1->c[i] != '\0'){ //basically, while there is a word
        if(s1->c[i] < s2->c[i]) // if string 1 char is less than string 2 char
            cs2++; //add to string 2 count
        else (s1->c[i] > s2->c[i]) //vice versa
            cs1++;
        i++;
    }

//for my return I basically have

        if(cs1>cs2){
         return 1;
    }
    else if(cs2 > cs1){
         return 2;
    }
    return 0;

here is mystring.h

typedef struct mystring {
    char * c;
    int length;

    int (*sLength)(void * s);
    char (*charAt)(void * s, int i);
    int (*compareTo)(void * s1, void * s2);
    struct mystring * (*concat)(void * s1, void * s2);
    struct mystring * (*subString)(void * s, int begin, int end);
    void (*printS)(void * s);

} string_t;
typedef string_t * String;

Any suggestions, all of my google searches involve using the <string.h> library, so I’ve had no luck.

Im using this to traverse through a linked list and remove the person whose last name matches the person the user is trying to delete.
Here is my test code to help clarify my problem (Note that compareto is in the remove function):

int main() {
    Node startnode, currentnode, newnode;
    int ans, success;
    String who;
    who = newString2();

    startnode = (Node) malloc(sizeof(pq_t));
    startnode->next = NULL;
    currentnode = startnode;
    ans = menu();
    while (ans != 0) {
        switch (ans) {
        case add:
            newnode = getStudent();
            startnode = insert(newnode, startnode);
            break;
        case remove:
            printf("Enter the last name of the person you want to delete : \n");
            scanf("%s", &who->c);
            startnode = removeStudent(startnode, who, &success);
            if (success == 0)
                printf("UNFOUND\n");
            else
                printf("permanently DELETED\n");
            break;

        case view:
            printf("Now displaying the list : \n");
            displaylist(startnode);
            break;
        }
        ans = menu();
    }
}

Node removeStudent(Node head, String who, int * success) {
    Node p, l; //p = pointer node, l = previous node
    Student current; //Im using generics, so I have to case the current node->obj as a student.
    String ln, cln; //the last name of the person I want to remove, and the last name of the current node

    p = head;
    l = p;
//there can be three cases, p->first node, p->last node, p->some node in between
    if (head->obj == NULL) { 
        printf("The list is empty\n"); //when the list is empty
        *success = 0;
        return NULL;
    }
    while (p != NULL) {
        current = (Student) p->obj;
        cln = current->ln;
        if (ln->compareTo(who, cln) == 0) {
            if (head == p) { //when there is only one node
                head = head->next;
                free(p);
                *success = 1;
                return head;
            } else if (p->next == NULL) { //last node
                l->next = NULL;
                free(p);
                *success = 1;
                return head;
            } else {
                l->next = p->next; //middle
                free(p);
                *success = 1;
                return head;
            }
        }
        l = p;
        p = p->next;
    }
    *success = 0;
    return head;//couldnt find the node
}
  • 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-14T03:46:18+00:00Added an answer on May 14, 2026 at 3:46 am

    Try comparing the following pairs of strings:

    “ABC” vs “DEF”

    “ADF” vs “BBB”

    “ABC” vs “CBA”

    What results do you get? More importantly, why? How do these results compare to what you want to get?

    (You should first work it out in your head. Work out the values of c1 and c2 for each step of the comparison loop.)

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

Sidebar

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't know about any open source flash paint (i… May 16, 2026 at 6:16 pm
  • Editorial Team
    Editorial Team added an answer Is it possible to load a layout XML at runtime… May 16, 2026 at 6:16 pm
  • Editorial Team
    Editorial Team added an answer In one of my projects I am using dompdf. Here… May 16, 2026 at 6:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

So basically the assignment was we had to create a doubly linked list that's
For an assignment we were given in Data Structures, we had to create a
Wrote up a basic file handler for a Java Homework assignment, and when I
Howdy. I am in a networking class and we are creating our own networking
template <class T> bool BST<T>::search(const T& x, int& len) const { return search(BT<T>::root, x);
First of all: this is not a homework assignment, it's for a hobby project
This is my assignment question: Explain with an example quick sort , merge sort
I'm not sure if this kind of question is appropriate, but its been suggested
I am a little confused about object assignment and pointers in Ruby, and coded
I was recently doing a programming assignment that required us to implement in code

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.