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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:02:05+00:00 2026-06-15T15:02:05+00:00

How can I remove first two elements of a string array? I have a

  • 0

How can I remove first two elements of a string array?
I have a code which is something like this.

char *x[10];
..............
..............
..............
char *event[20];
event[0]=strtok(x[i]," ");
event[1]=strtok(NULL," ");
event[2]=strtok(NULL," ");
event[3]=strtok(NULL," ");
event[4]=strtok(NULL," ");
event[5]=strtok(NULL," ");
for(i=2;i<length;i++)
{
    strcpy(event[i-2],event[i]);
}

I observed that only event[0] has proper values. I printed the contents of event[][] before for loop and it displays correctly. Could you please tell me why this is wrong? and a possible solution?

  • 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-15T15:02:12+00:00Added an answer on June 15, 2026 at 3:02 pm

    You should not be using strcpy() in this code. The API strtok() will return you a pointer to the delimited token discovered within the original source buffer after terminating at the discovered delimiter. Therefore, you’re using strcpy() where you should not be.

    Your events[] array has pointers returned from strtok(). Just throw out the first two pointers and move the others down:

    for(i=2;i<length;i++)
        event[i-2] = event[i];
    length -= min(length, 2);
    

    Note: the min() is required to ensure your length, signed or unsigned, never wraps below zero (if signed) or UINT_MAX (if unsigned) in the event length is undersized on entry.

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

Sidebar

Related Questions

I have an array like this Array['one','two','three','four','five'] and I have an array like this
I have two elements that share a label. I need to add/remove a CSS
I have two lists. At start only the first one has visible elements, the
I have a xml code that can ahve two forms : Form 1 <?xml
I have a somewhat grouping system which all the elements between two divs are
How we can remove an array entry from : var a = [],b =
I am wondering How i can remove a part if my string . For
This is a bit complex. I've created an array (NSArray) called pointsOfInterest. The elements
i have to switch in between two table as per users choice i can
I have a collection of strings which I need to perform two operations on.

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.