Thread: a grep c alternative?

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

    a grep c alternative?

    Hello folks,

    I need to use some regular expression searching of the dictionary. I can do a system call to grep, but I'm looking for portability with this program, and since grep is part of linux, I can't very well port my executable to the windows environment and expect it to run.

    The basic idea is:
    grep "h.*i.*" dictionary

    returning every word that has h followed by whatever and i followed by whatever.

    Is there any built in C function or open-source C program that we can utilize to accomplish this task?

    So instead we could do an:
    dict= fopen("dictionary", "r")
    regex_search(dict, "h.*i.*")

    Thanks folks.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You can use POSIX regex in any POSIX-compliant environment: regex(3): POSIX regex functions - Linux man page
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Since it sounds like you're using Linux, take a look here: Regular Expressions - The GNU C Library.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    25
    If I use regex and my program is compiled into some executable that regex should still work if the executable is run in another environment? Eventually I'm going to have to have a Java gui interacting with this C program (complicated stuff was coded in C and I don't have the knowledge of the content to rewrite it in Java)

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by drshmoo View Post
    If I use regex and my program is compiled into some executable that regex should still work if the executable is run in another environment?
    You're not going to be able to run, for instance, a Linux executable in Windows. Is that what you're asking?

    You will, however, be able to compile the same source code in both environments as long as you conform to standards.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. grep
    By Kennedy in forum Tech Board
    Replies: 2
    Last Post: 01-13-2011, 09:47 AM
  2. Redirecting stdin - freopen alternative
    By kaylaneko in forum C Programming
    Replies: 2
    Last Post: 12-13-2010, 07:07 PM
  3. programming with grep
    By George2 in forum Tech Board
    Replies: 4
    Last Post: 11-18-2006, 03:30 AM
  4. simple grep problem
    By cdave in forum Windows Programming
    Replies: 7
    Last Post: 12-29-2005, 05:48 PM
  5. Grep
    By cfriend in forum Linux Programming
    Replies: 3
    Last Post: 09-17-2004, 05:34 AM