Help

This is a discussion on Help within the C Programming forums, part of the General Programming Boards category; I'm trying to do a Program in DOS with the C Language and I'm stuck in one place I want ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    7

    Help

    I'm trying to do a Program in DOS with the C Language and I'm stuck in one place
    I want to do a program that searches a file for something I specify and I want to do it this way:
    tel electronic boutique
    In that example I want to find the telephone number in the file of electronic boutique , how do I put in a variable electronic boutique ?

    Hope someone can help me

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    Well if its just a text file, then
    - fopen/fclose to open/close the file
    - fgets to read each line in the file
    - strstr to match search strings

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    7
    But how can I get the match that I want to be in a variable like for example :
    tel Electronic Boutique
    * tel would be the program compiled
    * Electronic Boutique would be the match I want to find
    how can I put Electronic Boutique in a variable ?

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    do you have other things to search for besides telephone numbers?

    I would do something like this, have 1 program, a search program, that takes command line arguments.
    The first argument is what to search for (ie tel, addr)
    The rest of the arguments is what store/businness you are looking for.

    Then make a database text file with all the info.

    Electronic Boutique
    tel 1
    (123) 456-7890
    addr 4
    123 main st
    new york
    new york
    12345

    In this case the first line is the company, the next line is "tel 1" meaning the telephone info takes up the next 1 line.
    then "addr 4" means the address takes up the next 4 lines.

    You can store the information how ever you want to, but using a txt file is pretty easy.

    Then if i said "search tel Electronic Boutique" it would return (123) 456-7890
    and "search addr Electronic Boutique " it would return
    123 main st
    new york
    new york
    12345

    You can keep what ever info and stores you want to in the text file.

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    7
    What you said is good
    but in the file I have everything in one line for example:
    electronic boutique de plaza las americas.............................764-6858

    see that will be one line
    and I want to do with the C program that I put tel electronic boutique and then it searches for that in a loop line by line and prints me that exact line in the screen

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    Originally posted by fremaint
    ... and I want to do with the C program that I put tel electronic boutique and then it searches for that in a loop line by line and prints me that exact line in the screen
    Ok well you have to use the input from the user, in this case "electronic boutique" and compare that to the info in the file.
    You have a good idea of searching line by line, do you have any specific question

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    7
    How do I use the strstr to match search strings and how do I use fgets ?

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    http://www.rt.com/man/fgets.3.html
    http://www.rt.com/man/strstr.3.html

    A board search will provide you with some examples.....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

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