Thread: Reading Wrong values

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    2

    Reading Wrong values

    I need to get data form single line in my data file. I'm finding the right line, but i read all values as 0, no matter what it suppost to be.

    The start
    Code:
        int main(void)
    {
        file = fopen("data.csv", "r");
    
        printf("Enter the name of the currency wanted.\n");
        scanf("%s",&countryw);
    
        find_a_line();
    
        printf("%.2lf\n\n\n",&find_a_line);
    
        fclose(file);
    
        while( '\n' != getchar());
        getchar();
    
    return(0);
    }
    Finding and reading a specific line
    Code:
    double find_a_line(void)
    {
        lines = 1;
    
        for(i=0; i < lines; i++)
        {
    
            fscanf(file, "%s %lf", &country, &valuta);
    
            if(strcmpi(countryw,country) != 0)
            {
                lines ++;
            }
    
        }
    return valuta;
    }

    the data.csv file contains
    Code:
    EUR 0.130000
    USD 0.180000
    GBP 0.110000
    can someone figuer out why is read all values as 0.00?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > printf("%.2lf\n\n\n",&find_a_line);
    No & on printing.

    If you're using gcc, then add -Wall to your command line options.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    2
    Thx, donno why i allways make that mistake

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 04:50 PM
  2. Newbie at C, about reading floats into an array
    By someoney3000 in forum C Programming
    Replies: 9
    Last Post: 10-14-2009, 12:40 PM
  3. What am I doing wrong ?
    By scottjge in forum C Programming
    Replies: 6
    Last Post: 10-01-2009, 11:55 AM
  4. reading a string of hex values from command line
    By peeweearies in forum C Programming
    Replies: 7
    Last Post: 02-24-2009, 02:25 AM
  5. Replies: 1
    Last Post: 02-03-2005, 03:33 AM