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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:35:29+00:00 2026-05-30T11:35:29+00:00

Writing a program in which I need to split strings from a struct linked

  • 0

Writing a program in which I need to split strings from a struct linked list into pieces and recombine them. I then insert the new Strings back into the Linked List.

the struct I am using to build the nodes looks like this:

typedef struct CANDIDATENODE
{
char sentence[TARGET_LEN+1];
int rank;
int score;
int goodFlag;
struct CANDIDATENODE *next;

} Candidate;

(TARGET_LEN is the maximum string length. not Including the null terminator, which is the reason for the +1 in )

I encounter no segfaults or bus errors, but after the third character is copied, the next time through my string arrays are filled with characters that do not belong.
earlier in the program I fill 20 nodes in a linked list with random characters. It is from this list of Nodes that I am passing in the Candidate pointer

The clearPointer below points to the end of the linked list where I will be adding the new sentences.

Here is the Problem method in its entirety.

void breedSentences(Candidate *can1)
{

Candidate *can2 = can1->next;

char childOne[TARGET_LEN+1];
char childTwo[TARGET_LEN+1];

memset(childOne, '\0', sizeof(TARGET_LEN+1));
memset(childTwo, '\0', sizeof(TARGET_LEN+1));


printf("parent1:%s;\n", can1->sentence);
printf("parent2:%s;\n", can2->sentence);

int pivot1  = random() %TARGET_LEN-1;
int pivot2  = random() %TARGET_LEN-1;

printf("pivot1= %d\n", pivot1); 
printf("pivot2= %d\n", pivot2);     

int i;
for (i =0; i<TARGET_LEN-1; i++) 
{
    if (i<pivot1)
    {
        childOne[i]= can1->sentence[i];
    }
    else
    {
        childOne[i]= can2->sentence[i];
    }


    if (i<pivot2)
    {
        childTwo[i]= can1->sentence[i];
    }
    else
    {
        childTwo[i]= can2->sentence[i];
    }

    childOne[TARGET_LEN]= '\0';
    childTwo[TARGET_LEN]= '\0';

    printf("First:%c\n", can1->sentence[i]);
    printf("Second:%c\n", can2->sentence[i]);

    printf("1:%s\n", childOne);
    printf("2:%s\n", childTwo);

}





printf("%s\n", childOne);
printf("%s\n", childTwo);


strcpy(clearPointer->sentence, childOne);
clearPointer = clearPointer->next;

strcpy(clearPointer->sentence, childTwo);   
clearPointer = clearPointer->next->next; 



}
  • 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-30T11:35:31+00:00Added an answer on May 30, 2026 at 11:35 am

    Wiz’s comment under my question led me to the answer. making my allocated space too small caused my program to behave unexpectedly.

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

Sidebar

Related Questions

I am writing a C# program which captures signals from a external device, and
I wrote a program which includes writing and reading from database. When I run
I am writing a program in Ruby which will search for strings in text
I am writing a program in which I need to draw polygons of an
I'm about to start writing a program which will attempt to extract data from
I am writing a c++ program which sooner or later will need to be
I need to writing a Delphi program which will monitor a folder for changes
I'm writing a program which will need to do a very large number of
I am writing a program in which I need to get a random value
I'm writing a program in Common Lisp in which I need a function with

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.