Thread: Question on getline and the string funtions

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    8

    Question on getline and the string funtions

    Hello all,

    So I have this data input file...

    4 Recumbent_Exercise_Bike E C B S -1 -2 3 20.5 27.5 60.0 22.0 3 5
    50 Machine_Fly S A W W 30 40 0 15 18 1.8 30.0 10 2
    53 Machine_Bicep_Curl S A W W 30 50 0 10 18 3.25 45.0 20 4
    487 Yoga_Sun_Salutation F W M N -1 -2 2 1 3 112.0 1200.0 50 2
    221 Walk E C N N -1 -2 3 30.0 45.0 60.0 180.0 35 5
    488 Yoga_Downward_Dog F W M N -1 -2 2 1 3 20.0 300.0 50 12
    138 Crunch S W N N -1 -2 0 20 40 4.2 240 10 10
    222 Jog E C N N -1 -2 1 .5 1.25 150.5 5000 15 5
    134 Free_Weight_Bicep_Curl S A F W 15 25 0 8 14 4.5 200.0 10 50
    135 Free_Weight_Triceps_Curl S A F W 12 20 0 9 12 5.4 200 10 50
    9 Treadmill E L S S -1 -2 1 50.0 75.5 59.0 25.0 15 10
    6 Ski_Machine E W O R 30 50 3 7.5 12.5 60.0 15.0 12 12


    Now, I having difficulties trying to read each line from my input file by using getline.

    Another concerns, I'm trying to figure out which string function that I would need to use in order to go through each data that is separated by the white spaces. And then convert it to the correct type.


    Here's what I have so far...


    Code:
    
    
    int main( int argc, char *argv[] )
    {
            int choice, choice_1 = 0;
            int index, i, j, bytes_read, end_of_file = 0;
            FILE *exercisefile;
            struct program exercise = {NULL}; //Declaring a struct of programs called exercise
            struct program *head, *new, *current, *previous; //Declaring pointers
    
    
    
    
                    my_string = (char *) malloc (struct program + 1);                        
                    bytes_read = getline (&my_string, &struct programs, exercisefile);        
                    puts (my_string);

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You'll need to write your own getline. There's no such standard function. You probably want something like fgets, or to write your own using something like fgetc.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    187
    i think he has written it as a function right ?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    He's written a call to that function. But he hasn't actually defined that function anywhere in his code.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    187
    nvm i didnt see the subject of his question...
    Last edited by elwad; 04-29-2009 at 09:43 PM.

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by larry_2k4 View Post
    Hello all,

    So I have this data input file...

    4 Recumbent_Exercise_Bike E C B S -1 -2 3 20.5 27.5 60.0 22.0 3 5
    50 Machine_Fly S A W W 30 40 0 15 18 1.8 30.0 10 2
    53 Machine_Bicep_Curl S A W W 30 50 0 10 18 3.25 45.0 20 4
    487 Yoga_Sun_Salutation F W M N -1 -2 2 1 3 112.0 1200.0 50 2
    221 Walk E C N N -1 -2 3 30.0 45.0 60.0 180.0 35 5
    488 Yoga_Downward_Dog F W M N -1 -2 2 1 3 20.0 300.0 50 12
    138 Crunch S W N N -1 -2 0 20 40 4.2 240 10 10
    222 Jog E C N N -1 -2 1 .5 1.25 150.5 5000 15 5
    134 Free_Weight_Bicep_Curl S A F W 15 25 0 8 14 4.5 200.0 10 50
    135 Free_Weight_Triceps_Curl S A F W 12 20 0 9 12 5.4 200 10 50
    9 Treadmill E L S S -1 -2 1 50.0 75.5 59.0 25.0 15 10
    6 Ski_Machine E W O R 30 50 3 7.5 12.5 60.0 15.0 12 12


    Now, I having difficulties trying to read each line from my input file by using getline.

    Another concerns, I'm trying to figure out which string function that I would need to use in order to go through each data that is separated by the white spaces. And then convert it to the correct type.


    Here's what I have so far...


    Code:
    
    
    int main( int argc, char *argv[] )
    {
            int choice, choice_1 = 0;
            int index, i, j, bytes_read, end_of_file = 0;
            FILE *exercisefile;
            struct program exercise = {NULL}; //Declaring a struct of programs called exercise
            struct program *head, *new, *current, *previous; //Declaring pointers
    
    
    
    
                    my_string = (char *) malloc (struct program + 1);                        
                    bytes_read = getline (&my_string, &struct programs, exercisefile);        
                    puts (my_string);
    give us ur full code. If this is ur full code then it should have a return 0 and a ending curly brace. as quzah already told there is no such function getline in the standard library, but u can always write ur own and use it as u wish.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed