Thread: Help me thank you

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    5

    Angry Help me thank you

    The aim will show on the screen but does not show the contents of a file on the screen different shows. How do I fix it or how to do it



    Code:
    #include <stdio.h>
    #include <conio.h>
    main()
    {
    char filename[100];
    double xx;
    int ii, kk;
    FILE *infile;
    printf("Enter the file name:");
    scanf("%s",&filename);
    infile=fopen(filename,"r");
    fscanf(infile,"%d",&ii);
    fscanf(infile, "%d %lf",&kk,&xx);
    fclose(infile);
    printf("ii=%d,kk=%d \n xx=%lf\n",ii,kk,xx);
    }


    Help me thank you-ads-z-jpg

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Welcome to the forum, did the file opened properly? Does it exist?
    Do a null pointer check for the infile pointer and find out, right after the fopen().
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You have to post the same code, as the code you are working with. Note that in line #10, you have one line with the &filename, and one line #10, with just the filename.

    The later one is correct.

    If you need more help with fscanf(), you will have to post the input line it is is trying to read, EXACTLY as it appears in the file. fscanf() is fussy, and everything must be spot on for it to work.

    Putting in some checks to see if the file opened, etc., (as mentioned above), is another very good idea.

  4. #4
    Registered User
    Join Date
    Nov 2013
    Posts
    5
    Quote Originally Posted by Adak View Post
    You have to post the same code, as the code you are working with. Note that in line #10, you have one line with the &filename, and one line #10, with just the filename.

    The later one is correct.

    If you need more help with fscanf(), you will have to post the input line it is is trying to read, EXACTLY as it appears in the file. fscanf() is fussy, and everything must be spot on for it to work.

    Putting in some checks to see if the file opened, etc., (as mentioned above), is another very good idea.
    I want you to write directly. to run in.PLEASE

  5. #5
    Registered User
    Join Date
    Nov 2013
    Posts
    5
    Quote Originally Posted by std10093 View Post
    Welcome to the forum, did the file opened properly? Does it exist?
    Do a null pointer check for the infile pointer and find out, right after the fopen().

    I want you to write directly. to run in.PLEASE

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I can't "write directly" because I don't see the input data you are trying to read. You can't read data with fscanf() without knowing what the format of the data is.

  7. #7
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by alper1059 View Post
    I want you to write directly. to run in.PLEASE
    Adak is way too polite with you. Are you **ordering** us to do your homework? :O

    I mean, Adak spotted a very detailed "&", that was not the same in the piece of code you posted and in the screenshot. Moreover, he volunteered (for FREE) to make the best he can for your fscanf().
    He needs the data to do that, but you do not seem to care at all.
    And there's mine post too, suggesting you to check, but you don't even bother to check the NULL pointer, right? You wait that we, must know what is inside your workspace and what's your data.

    I can not find the rules of the forum (never could to be honest), but the forum surely does not serve the role of "Post your hw here and we answer back with the solution". This forum is to help each other learn and get better. Moreover, beginners can get benefited from it much, just like I did in 2010, when I entered the cs uni and then, around Christmas, this forum. I was a beginner then and you can not imagine how things I learned (I woudln't believe it if someone told me that I was going to learn all these things). I am still, of course, learning. Learning, is a life-time process!
    The hw policy goes **something** like this:
    • You post your question.
    • We answer back, suggesting you what to do, make you learn (if you are willing to) new things and MANY more.
    • We expect you to do them and report back if you are ok or not.
    • If not, go to the first dot, if yes, we are done.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #8
    Registered User
    Join Date
    Nov 2013
    Posts
    5
    Quote Originally Posted by std10093 View Post
    Adak is way too polite with you. Are you **ordering** us to do your homework? :O

    I mean, Adak spotted a very detailed "&", that was not the same in the piece of code you posted and in the screenshot. Moreover, he volunteered (for FREE) to make the best he can for your fscanf().
    He needs the data to do that, but you do not seem to care at all.
    And there's mine post too, suggesting you to check, but you don't even bother to check the NULL pointer, right? You wait that we, must know what is inside your workspace and what's your data.

    I can not find the rules of the forum (never could to be honest), but the forum surely does not serve the role of "Post your hw here and we answer back with the solution". This forum is to help each other learn and get better. Moreover, beginners can get benefited from it much, just like I did in 2010, when I entered the cs uni and then, around Christmas, this forum. I was a beginner then and you can not imagine how things I learned (I woudln't believe it if someone told me that I was going to learn all these things). I am still, of course, learning. Learning, is a life-time process!
    The hw policy goes **something** like this:
    • You post your question.
    • We answer back, suggesting you what to do, make you learn (if you are willing to) new things and MANY more.
    • We expect you to do them and report back if you are ok or not.
    • If not, go to the first dot, if yes, we are done.

    I do not see my mistake. I want to help you

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by std10093 View Post
    Adak is way too polite with you. Are you **ordering** us to do your homework? :O
    I suspect part of the problem is that alper1059 is not a native english speaker, so his/her mode of expression conveys unintended meaning (things being lost or gained in translation).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  10. #10
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by alper1059 View Post
    I do not see my mistake. I want to help you
    Ok, good.
    Quote Originally Posted by grumpy View Post
    I suspect part of the problem is that alper1059 is not a native english speaker, so his/her mode of expression conveys unintended meaning (things being lost or gained in translation).
    If that is the case, then it's all ok!
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  11. #11
    Registered User
    Join Date
    Nov 2013
    Posts
    5
    Quote Originally Posted by std10093 View Post
    Ok, good.

    If that is the case, then it's all ok!
    What case ?

    can you write ? program

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    4,509
    If you haven't figured it out yet, nobody is going to do your work for you.

    Announcements - General Programming Boards

    In fact, even if someone for some reason wanted to do your work for you (not likely), they still couldn't because you haven't provided the information requested several times.

    The members of this forum are here to answer questions and guide you towards a solution. For this arrangement to work, you need to (1) listen to what is said, (2) provide additional information that is requested, and (3) apply the advice you receive in an attempt to solve the problem yourself.

    And while we're at it, could somebody please explain the whole "starting a thread title with an angry face" phenomenon? I'm not sure what this is supposed to convey. Frustration, perhaps?

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You post numbers in file - then we help.

Popular pages Recent additions subscribe to a feed