Thread: Sscanf Issues and getting rid of quotes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    34

    Sscanf Issues and getting rid of quotes

    I am trying to read from a file , that contains.

    "15668942" "TOYOTA" "ENGINE PISTON" 12.50 8
    "68465245" "NISSAN" "STARTER" 50.20 14
    "14134455" "MITSUBISHI" "STEERING WHEEL" 20.00 0
    "31457645" "SUBARU" "TURBO" 3000.00 5
    $$$$$$$$$$

    I tried using sscanf. When the files reaches $$$$$ it should stop reading from the file. I havent able to get the $$$ to work as yet so i used NULL.

    My problem is 2 things.

    1) When I use sscanf and i Print it, it got the number correct, and the word toyota correct. When it came to engine piston, it took up to "engine " and used the rest for the double variable it seems to me because the output for the double and integer are crazy numbers.


    Code:
    while(fgets(line,100,in)!=NULL)
    {
    sscanf(line, "%s %s %s %e %d",number,name,description,&unit_price,&quantity_in_stock);
                printf("%s %s %s %e %d\n",number,name,description,unit_price,quantity_in_stock);
    }
    2) When I do get the values and strings in their variables, I also get the quotes. I would like to get rid of those quotes. I tried using strtok but I am getting trouble for it to take off the " because of the syntax. For example

    Code:
    resule=strtok(name,""");
    I know this does not work lol.

    Any advice.
    Last edited by Ramkiller1; 10-27-2012 at 08:03 PM. Reason: Yes, I know I should be using sizeof() instead of 100

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sscanf() issues
    By Stiletto in forum C Programming
    Replies: 11
    Last Post: 12-19-2011, 02:59 PM
  2. Computer Quotes
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-01-2003, 08:31 AM
  3. Quotes in Quotes?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 01-12-2003, 04:48 PM
  4. Quotes
    By whistlenm1 in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-31-2002, 09:28 AM
  5. outputing quotes(') and double quotes(")
    By lostboy in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 02-26-2002, 06:17 PM