Comparing Strings

This is a discussion on Comparing Strings within the C Programming forums, part of the General Programming Boards category; Ok, i should know this but i can't remember the function Code: char name[20] = "Bob"; if (name == "Bob"){ ...

  1. #1
    Registered User zdude's Avatar
    Join Date
    Sep 2002
    Posts
    32

    Comparing Strings

    Ok, i should know this but i can't remember the function

    Code:
    char name[20] = "Bob";
    
    if (name == "Bob"){ // Invalid, need real funtion
      printf("true");
    }
    How do i compare 2 strings to test whether they are equal?
    Those who live by the sword get shot by those who don't.

    I can C.

    Compiler: gcc

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    strcmp
    strncmp

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  2. Problem with comparing strings!
    By adrian2009 in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 09:44 PM
  3. comparing strings using argv
    By eth0 in forum C Programming
    Replies: 2
    Last Post: 09-20-2005, 09:20 AM
  4. comparing strings
    By infinitum in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2003, 12:10 PM
  5. Comparing Strings
    By Perica in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2003, 10:41 PM

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