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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:37:41+00:00 2026-06-13T14:37:41+00:00

I am trying to write a method that removes the first letter of a

  • 0

I am trying to write a method that removes the first letter of a string and appends it to the end of the string with “ay” appended afterwards. I am using a linked list structure, and it works, but something is not 100% and I can’t figure out why. It does what is’t supposed to sometimes, but it seems to randomly add on parts of previous words. for example, the input “what the hell is wrong” should result as an output of “hatway hetay ellhay siay rongway”, but it gives me “hatway hetwayay ellhayayay silhayayayay rongway”

Here is the piece that seems to have the bug:

typedef struct  wordNodeType
{
    char word[MAX_CHARS];
    struct wordNodeType *next;// pointer to next node
}WordNode;

struct wordNodeType *tempP;

WordNode* translateWord (WordNode* nextWord)
{
    strcpy(e,nextWord->word);
    strcpy(p, &e[strlen(e)-(strlen(e)-1)]);// remove first letter
    // remove newline char if there
    if(p[strlen(p)-1] == '\n')
        p[strlen(p)-1] = '\0';
    p[strlen(p)] = e[0];//move first char of e to last char of p ***the problem seems to happen here
    strcat(p,"ay");// append "tay" to end
    strcpy(tempP->word,p);
    return tempP;
}

I have memory allocated for the nodes, and the node does have a value in “word.” The rest of my code works fine except for this minor bug that’s driving me crazy! Any thoughts?

  • 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-13T14:37:42+00:00Added an answer on June 13, 2026 at 2:37 pm

    There is a little change that needs to be done to fix this. Here is the changed code:

    WordNode* translateWord (WordNode* nextWord)
    {
        strcpy(e,nextWord->word);
        strcpy(p, &e[strlen(e)-(strlen(e)-1)]);// remove first letter
        // remove newline char if there
        if(p[strlen(p)-1] == '\n')
            p[strlen(p)-1] = '\0';
    int sizeofP = strlen(p);   /////Change Here
        p[strlen(p)] = e[0];//move first char of e to last char of p ***the problem seems to happen here
    p[sizeofP + 1] = '\0';  /////Change Here
        strcat(p,"ay");// append "tay" to end
        strcpy(tempP->word,p);
        return tempP;
    }
    

    The problem was that when you wrote First character at the end of p, you overwrote the '\0' character and hence there was no way to reach the end of the string.

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

Sidebar

Related Questions

I'm trying to write a method that removes all non alphabetic characters from a
I’m trying to write a regex/method that extracts Variables from an input String that
I am trying to write a method in Java that accepts a string as
I'm trying to write a method that will compute all permutations of a power
I am trying to write a method that adapts to different types of interfaces
I'm trying to write a method that acts as a setter and takes some
I am trying to write a method that makes a log.txt file if one
I am trying to write a method that reads the contents of a richtext
I am trying to write a generic method that would bind any asp.net UI
I am trying to write an Audit Log method that will log all changes

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.