Thread: Hi i have a little issue

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    1

    Hi i have a little issue

    Hi everyone,
    I am new to this forum so welcome,
    i also have a knowledge in java so feel free to ask me.

    Since i am new to c ,
    i have this question:

    Code:
    char str5[]="abcabbacda",ch='a';
    char * pos;
    
     
     
    pos = strchr(&str5[1], ch);
    
     
    			
    if(pos!=NULL)
     
     
    
     
    			{ 
    
     
    			printf(
    "%p ", pos);
    
     
    			}
    
    why is this not NULL?
    since str[1]=='b' and not 'a'.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Refer to what strchr does:
    Quote Originally Posted by C11 Clause 7.24.5.2
    Code:
    #include <string.h>
    char *strchr(const char *s, int c);
    The strchr function locates the first occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be part of the string.

    The strchr function returns a pointer to the located character, or a null pointer if the character does not occur in the string.
    In the string "bcabbacda" (i.e., we exclude the first character of the original string since you had the substring start from index 1 of the original string), 'a' does occur, hence strchr will locate that occurrence and return a pointer to it rather than a null pointer.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another Big Issue (2)
    By claw046 in forum C++ Programming
    Replies: 14
    Last Post: 03-23-2014, 01:00 AM
  2. Another big issue
    By albireo in forum C++ Programming
    Replies: 40
    Last Post: 03-22-2014, 05:24 PM
  3. Yet another EOF issue
    By kkk in forum C Programming
    Replies: 4
    Last Post: 09-01-2011, 10:52 AM
  4. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  5. new issue
    By hiddenprophecy in forum C Programming
    Replies: 3
    Last Post: 04-15-2009, 05:59 PM