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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:39:41+00:00 2026-05-26T02:39:41+00:00

I found a weird problem when I was learning the strtok function. At first

  • 0

I found a weird problem when I was learning the “strtok” function.
At first I missed a header file when writing a demo program as follows:

/* strtok example */
#include <stdio.h>
//#include <string.h> // the header file I've missed at first

int main ()
{
    char str[] ="- This, a sample string.";
    char * pch;
    printf ("Splitting string \"%s\" into tokens:\n",str);
    pch = strtok (str," ,.-");
    while (pch != NULL)
    {   
        printf ("%s\n",pch);
        pch = strtok (NULL, " ,.-");
    }   
    return 0;
}

The compiler didn’t give any error message and successfully compiled the program. But it lead to a segmentation fault when running. And when I added the missing header file, everything went well.

My question is why the compiler didn’t diagnose any errors for the first compilation. I compiled it under Mac OS X with gcc4.2.1.

  • 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-26T02:39:41+00:00Added an answer on May 26, 2026 at 2:39 am

    In C, functions were allowed to have no prototypes (declarations). There would be no parameter conversions when calling such functions. Eg.:

    f(0);
    

    would call a function named f with a parameter (int)0 even when f was not declared. This results in undefined behavior (…segfaults…) when the actual definition of f (in another .c file, or in a library) was eg. int f(char*) or int f(long). This is not good practice, but is retained for backwards compatibility with original C.

    When the prototype is present, the compiler would automatically convert parameter to required types (possibly issuing an error) at call site.

    PS: don’t get me wrong thinking int is the default. What the compiler actually calls is entirely dependent on the call parameters. Eg. f(1.1) would match with void f(double), f("string") with f(char*).

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

Sidebar

Related Questions

I think I found a weird problem in Symfony. Here's my upload case form:
I found a weird problem with MySQL select statement having IN in where clause:
I am having a weird problem. I read a text file then I split
I have this weird gridview problem in .net, I haven't found what can be
I am writing a node.js server and i am experiencing a weird problem heres
I've been working on some custom graphics controls, and I found this weird problem
Today I found a weird problem, I was trying to fire a DropDownList SelectedIndexChanged
I've found a weird effect when trying to track down a memory leak in
I believe I have found a weird bug as follow: I want to delete
I'm running Windows 7 with UAC enabled . I've always found it weird that

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.