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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:07:53+00:00 2026-06-14T13:07:53+00:00

On my system, the following program: int main(){ char *strgptr; char buf[5] = {‘b’,’a’,’a’,’a’,’\0′};

  • 0

On my system, the following program:

int main(){
        char *strgptr;
        char buf[5] = {'b','a','a','a','\0'};
        char *tmp = strtok_r(buf, ".", &strgptr);
        if(tmp != NULL){
                printf("Found a . in baaa?\n");
                printf("It was found starting at: %s\n", tmp);
        }
        else
                printf("Everything is working.\n");
}

prints:

Found a . in baaa?
It was found starting at: baaa

However, if I swap the “.” delimiter string in strtok_r for “a”, I get (as expected):

Found a . in baaa?
It was found starting at: b

But swapping the “.” for any other char not appearing in buf (e.g. “c”) produces:

Found a . in baaa?
It was found starting at: baaa

The man page for strtok_r, as expected, says:

The strtok() and strtok_r() functions return a pointer to the next token, 
or NULL if there are no more tokens.

So why does strtok_r fail to return NULL when passed a string which contains none of the tokens in question?

  • 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-14T13:07:55+00:00Added an answer on June 14, 2026 at 1:07 pm

    Because the delimiter isn’t found, so you’re getting the whole string returned. It acts as if there’s an invisible delimiter after the string.

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

Sidebar

Related Questions

I have the following program: int main(int argc, char *argv[]) { int a, b;
I have the following two programs: long startTime = System.currentTimeMillis(); for (int i =
I have the following MonoTouch program: using System.Drawing; using MonoTouch.Foundation; using MonoTouch.UIKit; using System;
Consider the following code: using System; namespace ConsoleApplication2 { class Program { static void
#include <my_global.h> #include <mysql.h> int main(int argc, char **argv) { printf(MySQL client version: %s\n,
See the following program: #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> main(void){ printf(Array
I am trying to use the system calls read() and write(). The following program
In the following program class ZiggyTest2 { public static void main(String[] args){ double x
Depending on the compiler the following code: int main() { srand( 0 ); if(
I have the following piece of code: #include <stdio.h> #include <stdlib.h> int main(int argc,

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.