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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:25:12+00:00 2026-05-30T15:25:12+00:00

If I have: char *tokenPtr = testingpointerindex and I want to access everything after

  • 0

If I have:

char *tokenPtr = "testingpointerindex"

and I want to access everything after the 4th character, how would I go about that? I tried :

char *tokenPtr = "testingpointerindex";

char *host = tokenPtr + 4;
printf("%s\n",host);

return host;

It’s just an outake but I hope it gives enough info, I get a bus error.
Thanks

EDIT:

The full code

char * getHost(char *buf){
char *tokenPtr;
tokenPtr = strtok(buf, "\r\n" ); 
printf("got token\n");
while ( tokenPtr != NULL ) { 
    if(strncmp(tokenPtr,"Host",4) == 0){
        break;
    }
    else{
        tokenPtr = strtok( NULL, "\r\n" );
    }
}
char *host = tokenPtr + 7;
printf("%s\n",host);
    return host;
}
int main(int argc, char *argv[])
{
char *msg = "GET /index.html HTTP/1.1\r\n Host: www.google.com\r\n\r\n";
getHost(msg);


}
  • 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-30T15:25:14+00:00Added an answer on May 30, 2026 at 3:25 pm

    The above code works fine.

    However, there’s one thing to mention: string literals (e.g. "testingpointerindex") are non-modifiable in C. Therefore you should use const char *, not char *.

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

Sidebar

Related Questions

I have a char array in a C application that I have to split
I have a char array buffer that I am using to store characters that
I have some char() fields in a DBF table that were left encrypted by
I have a char pointer which would be used to store a string. It
I have unsigned char* , want to convert it to std::string . Can you
I am bit confused about how Java handle conversion. I have char array consist
I have a char [] , and I want to set the value of
I have a char array which contains null characters at random locations. I tried
I have a char buf[x] , int s and void* data . I want
I have a char array which contains some value . I want to copy

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.