Thread: Case sensitive

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    1

    Case sensitive

    Hi,

    I am using a string to compare A and S with tmp which can be a upper case value or a lower case value so i wrote a program like this
    <code>
    if(strstr(tmp,"A")!=NULL || strstr(tmp,"S")!=NULL) || strstr(tmp,"s")!=NULL || strstr(tmp,"a")!=NULL)
    </code>
    Is there a different way of writing the case sensitive letter can i use && operator and write a code
    Last edited by soled_boy; 02-02-2009 at 01:55 PM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Well, actually, you're trying to do a case insensitive comparison

    The more usual technique would be to convert tmp to upper/lower case (you call as to whether upper or lower), and then do your test. By definition, a string converted to uppercase will never contain lowercase characters and vice versa.

    If the case of other parts of tmp matter in later code, convert a copy of tmp to upper/lower case, and do the test against the copy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Intel syntax on MinGW ?
    By TmX in forum Tech Board
    Replies: 2
    Last Post: 01-06-2007, 09:44 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. returning to a spot in the code
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 09-22-2001, 05:24 AM