Thread: how to parse a string?

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    14

    Lightbulb how to parse a string?

    hello,

    I need a help . how to parse a string in c.

    also, how to get the avilable commands by putting first letter and click tab key.

    i.e., like linux,

    when i put "l", and click tab, it show ls,lockfile, locat etc.


    how to do it in C?.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    have you searched the forum? http://cboard.cprogramming.com/searc...earchid=597083
    (and maybe google http://www.google.co.il/search?hl=ru&q=parse+string+C)?
    Have you tried the some of the results?
    Encountered problems?
    Then post your attemp and ask question about the code.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Umm . . . vart, your first link turns up no hits.
    also, how to get the avilable commands by putting first letter and click tab key.

    i.e., like linux,

    when i put "l", and click tab, it show ls,lockfile, locat etc.


    how to do it in C?.
    That's more complicated. You'd have to get a list of the commands (perhaps by listing all the files in a directory, and discarding the files that aren't executable), then search for files starting with your string. (I would definitely sort the list in this case.)

    So, look up opendir(), readdir(), and closedir() for listing all the files in a directory. Also see this FAQ entry: http://faq.cprogramming.com/cgi-bin/...&id=1044780608

    Then look up some sorting algorithms, perhaps the insertion sort.

    Then parse the list of files with strcmp(), finding the first and last match, perhaps making use of binary searching.

    Or just execute this command:
    Code:
    system("ls -1F start* | grep '*$'");
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by dwks
    Umm . . . vart, your first link turns up no hits.
    Ups - it seems to be timed out...
    Haven't noted that instead of the search terms it uses search id...

    parse string - that what I've searched

    Also forgot to edit the google serch link to remove the hl=ru
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM