first characters in a string

This is a discussion on first characters in a string within the C Programming forums, part of the General Programming Boards category; can anyone tell me how i would detect if "http://" was the first part of a string? eg "http://example.com" would ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    10

    Exclamation first characters in a string

    can anyone tell me how i would detect if "http://" was the first part of a string?

    eg "http://example.com" would be detected however "example.com" would not

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The standard library is your friend. strstr


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    yes, but what if they enter "exahttp://ple.com" http still their but was not detected first, how can i make it so it has to be first, any ideas?

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    char a[] =  "exahttp://ple.com";
    char *s;
      s = strstr(a,"http");
      if(s == a) {                  // found it at first
        printf("got it!\n");
      } else {                           //( found it but not at first ) or not in a
       printf("No\n");
    }
    Last edited by Bayint Naung; 03-27-2011 at 08:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unable to compare string with 'getter' returned string.
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2009, 06:56 PM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 10:19 AM
  4. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM

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