strstr

This is a discussion on strstr within the C Programming forums, part of the General Programming Boards category; I have the char *ptr returned form strstr, but I am wondering how to get it to be an index ...

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    strstr

    I have the char *ptr returned form strstr, but I am wondering how to get it to be an index in an array
    Code:
    char *ptr;
    char string[]="This is a string\n");
    char what_to_look_for[]="a string");
    
    if((ptr=strstr(string,what_to_look_for))!=NULL){
         printf("Found it...It is the %ith character",???);
    }
    I have tried typecasting it to an int, but it gives me the memory address. Does anyone have any ideas?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    string[ptr - string]
    Last edited by Thantos; 05-21-2004 at 06:25 PM.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I freagin knew that. I couldn't think of it thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create Copies of Files
    By Kanshu in forum C++ Programming
    Replies: 13
    Last Post: 05-09-2009, 07:53 AM
  2. Quick Ques on String Manipulation
    By ckuttruff in forum C Programming
    Replies: 8
    Last Post: 06-22-2008, 09:32 PM
  3. linked list using strstr
    By ilovec.. in forum C Programming
    Replies: 3
    Last Post: 11-04-2006, 12:30 PM
  4. strstr on a wchar array
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-28-2006, 06:42 AM
  5. Question about strstr()
    By choykawairicky in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2004, 07:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21