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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:45:00+00:00 2026-05-17T21:45:00+00:00

I am doing something in C which requires use of the strings (as most

  • 0

I am doing something in C which requires use of the strings (as most programs do).

Looking in the manpages, I found, at string(3):

SYNOPSIS

#include <strings.h>

char * index(const char *s, int c)

(...)

#include <string.h>

char * strchr(const char *s, int c)

So I curiously looked at both strchr(3) and index(3)…

And I found that both do the following:

The strchr()/index() function locates the first occurrence of c in the string
pointed to by s. The terminating null character is considered to be part of the
string; therefore if c is ‘\0’, the functions locate the terminating ‘\0’.

So, the manpage is basically a copy & paste.

Besides, I suppose that, because of some obfuscated necessity, the second parameter has type int, but is, in fact, a char. I think I am not wrong, but can anyone explain to me why is it an int, not a char?

If they are both the same, which one is more compatible across versions, and if not, which’s the difference?

  • 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-17T21:45:00+00:00Added an answer on May 17, 2026 at 9:45 pm

    strchr() is part of the C standard library. index() is a now deprecated POSIX function. The POSIX specification recommends implementing index() as a macro that expands to a call to strchr().

    Since index() is deprecated in POSIX and not part of the C standard library, you should use strchr().

    The second parameter is of type int because these functions predate function prototypes. See also https://stackoverflow.com/a/5919802/ for more information on this.

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

Sidebar

Related Questions

Assume you are doing something like the following List<string> myitems = new List<string> {
I came across programs like ARCserve HA, which use windows session credentials as the
Doing some client-side JavaScript development, which requires me to call a client-side API which
I'm doing something bad in my ASP.NET app. It could be the any number
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Not that I'm doing something like that, but I am kind of interested how
I'm doing something like the following: SELECT * FROM table WHERE user='$user'; $myrow =
Am I doing something wrong or is it not possible to specify a generic
Currently I'm doing something like this in markup <input type=text ONKEYPRESS=InputNumeric(event); id=txtNumber /> But
I'm doing something like this: @protocol CallbackDelegate -(void) performCallback; @end @interface MyObject : NSObject

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.