assigning different values to the underscore char

This is a discussion on assigning different values to the underscore char within the C Programming forums, part of the General Programming Boards category; I have tried to find an answer to this for a couple of hours with no luck. It's probably something ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    Question assigning different values to the underscore char

    I have tried to find an answer to this for a couple of hours with no luck. It's probably something really simple but here it goes.

    I am building a search program which searches a file (which is supplied as one of the arguments) for a word/pattern I imput as one of the other arguments.

    The problem I have is that the pattern or search word can include the '_' character and that that character represents all the characters a - z as well as A - Z.

    Now I just don't know how i can define that underscore character to be all those letters, so that when for example I search for a_e, that it finds words are, ate and so on.

    I don't need help with anything else in coding (so far), just a simple example or hint on how I can accomplish the above.

    thanx in advance!
    Last edited by hyperactive; 03-19-2006 at 02:45 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    If the current match character is underscore, then test the input character is isalpha()
    See ctype.h
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    Thank you for you reply and i see what you mean. If I wanted to implement this into the code I would have to store both the search pattern and the string to be compared to into arrays and check if each of the characters of the search pattern has an underscore. If so check that the string to be compared to has a letter in place where the underscore was and repeat the process. The only problem with this is that it requires a lot of code and lot of detail. Is ther any other way of defining the underscore character to be in a specific range of an ascii character set for example, or something else that doesn't require me to go into such small detail (comparing letters with each other)?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Or you could just grab the source code for say regex and see how it's managed there.

    Unless you're specifically setting out to do it yourself, just re-using an existing library would be the way to go IMO.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unkown Hang
    By Bladactania in forum C Programming
    Replies: 31
    Last Post: 04-22-2009, 10:33 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  3. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 09:54 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM
  5. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 09:21 AM

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