Converting Strings To Integer In Linked List

This is a discussion on Converting Strings To Integer In Linked List within the C Programming forums, part of the General Programming Boards category; Does anybody know how I could get a string value from a file convert it to integer so I can ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    6

    Converting Strings To Integer In Linked List

    Does anybody know how I could get a string value from a file convert it to integer so I can do calculations and stuff, any help will be greatly appreicated

    This is the code I got so far

    temp_totalprice1=atoi(Stock.RetailPrice);
    temp_quantitysold1=atoi(temp_quantitysold);
    temp_totalprice1=temp_totalprice1*temp_quantitysol d;

    On the above code it doesn't assign the value of (Stock.RetailPrice) to temp_totalprice

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    181
    here is a code which could help u out a bit using struct

    Code:
    #include<stdio.h>
    
    struct temp
    {
        char price[10];
    };
    
    int main()
    {
        struct temp stock={"125"};
        int price;
        
        price=atoi(stock.price);
        
        printf("After converion using atoi %d",price);
        
        getchar();
        return 0;
    }
    my output
    Code:
    After conversion using atoi 125
    s. s. harish

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    How about:
    Code:
    temp_totalprice1 = temp_totalprice1 * temp_quantitysold1;
    and of course it doesn't assign the int price to temp_totalprice - you have it assigning to temp_totalprice1
    Last edited by Karthur; 06-05-2005 at 01:06 PM. Reason: formatting

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    6
    Hi S.S.Harish

    I did try your example and it works, I am getting the value but when I try to multiply the value with temp_quantitysold getting a error message “Illegal use of pointer”

    This is the code I got so far

    struct Stock RetailPrice;
    int price;

    temp_totalprice1=atoi(Stock.RetailPrice);
    temp_totalprice1=temp_totalprice1*temp_quantitysol d;



    Cheers
    Vish
    Last edited by rocky8015; 06-05-2005 at 10:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  3. Replies: 6
    Last Post: 03-02-2005, 01:45 AM
  4. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 06:29 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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