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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:56:06+00:00 2026-06-16T23:56:06+00:00

I have the following code: (I kept only the relevant part for my question)

  • 0

I have the following code:
(I kept only the relevant part for my question)

        // Structure
        struct first_list {
            char firstname[100];
            struct first_list * next;
        };
        struct last_list {
            char lastname[100];
            struct last_list * next;
        };

        void verify_name()
        {
            char firstname[100];
            char lastname[100];
            struct first_list * curr_first = loaded_first;
            struct last_list * curr_last = loaded_last;

        /////////// this part was added by me
            while( curr_last != NULL )
            {
                strncpy(lastname, curr_last->lastname, sizeof( lastname ) - 1 );
                valid = validate_name(sock,buffer,sizeof(buffer),firstname);
                if(valid < 1)
                    fprintf(stderr, "%s is VALID\n", lastname);
                else
                    fprintf(stderr, "%s is invalid\n", lastname);

                curr_last = curr_last->next; //this is used for removing current record

            }
            printf( "LastName validation complete\n" );
            break;
        /////////// end of part added by me

            while( curr_last != NULL && curr_first != NULL )
            {
                strncpy(firstname, curr_first->firstname, sizeof( firstname ) - 1 );
                strncpy(lastname, curr_last->lastname, sizeof( lastname ) - 1 );

                ////////////////////////////////
                //// irrelevant code (functions)
                ////////////////////////////////

                if( curr_first->next == NULL && curr_last->next != NULL)
                {
                    curr_last = curr_last->next;
                    curr_first = loaded_first;
                }
                else 
                    curr_first = curr_first->next;
            }
        }

so, I added a new function to validate lastnames before the function which validates firstnames and lastnames at the same time (to optimize the whole process). The problem is that if I remove the break command I get an error cause last_list is empty after validation.

How can I keep only the valid last names in the structure because right now when is moving to the next record it is deleting the current one until loop is complete(NULL) ??

  • 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-16T23:56:08+00:00Added an answer on June 16, 2026 at 11:56 pm

    What you need to do in your first loop is:

    struct last_list * prev = NULL;
    struct last_list * next = NULL;
    while (curr_last != NULL)
    {
      next = curr_last->next;
      strncpy(lastname, curr_last->lastname, sizeof(lastname) - 1);
      lastname[sizeof(lastname) - 1] = 0;
      valid = validate_name(sock,buffer,sizeof(buffer),firstname);
      if(valid < 1)
      {
        fprintf(stderr, "%s is VALID\n", lastname);
        prev = curr_last;
      }
      else
      {
        fprintf(stderr, "%s is invalid\n", lastname);
        if (prev == NULL)
          loaded_last = curr_last->next;  //this is used for removing when current is first record
        else
          prev->next = curr_last->next; //this is used for removing current record from mid-list
        free(curr_last); //Freeing should be needed but depends on how you built your list.
      }
      curr_last = next;
    }
    curr_last = loaded_last;
    

    This will remove your curr_last element from the list and retain only valid lastnames in it.

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

Sidebar

Related Questions

I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code for loading image from url in xml parsing endElement method
I have following code for inserting data into database using PDO. It inserts data
I have following code. ASPX Page <a href=AnyASPXPageOfWebsite.aspx onclick=javascript:CallJQuery(); > Set Price </a> JS
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code using hibernate to throw a custom exception on error and
I have following code: def whatever(url, data=None): req = urllib2.Request(url) res = urllib2.urlopen(req, data)
I have following code written to run NSTimer . But the NSTimer selector is

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.