Concerning gets() and fgets()

This is a discussion on Concerning gets() and fgets() within the C Programming forums, part of the General Programming Boards category; That is not really important . The guy will now the limit of the string. I am just trying to ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    151

    Concerning gets() and fgets()

    That is not really important . The guy will now the limit of the string. I am just trying to use the shortest function not to get tired =)

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by ozumsafa View Post
    That is not really important . The guy will now the limit of the string. I am just trying to use the shortest function not to get tired =)
    Stop making excuses, it is important.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    What are you talking about , I am sure guy has a brain to use , and gets is a short function which is useful when you are trying your algorith if it is working.Why would I use a function like fgets(blablalblalblall) ?? It is a must when you are writing a program for a real usage . Stop teaching around!!

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    gets() is not safe, and as such, it's deprecated. If someone seriously can't write the proper code to use fgets(), something is seriously wrong with their C coding ability and they should learn how to use the function.

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    "Why would I drive on the right hand side of the road? It's easier to drive in the middle"

    Read the FAQ regarding gets.

  6. #6
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    Is it hard to get?Using c codes is like doing the 4+5 math problem. I just say. When trying your algorithm , gets is shorter and faster to write , so when you are executing the program repeatedly lines dont play hard to change !! Goddd.

  7. #7
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    Sorry for overreacting , I am just trying to tell you , I am not a kid here messing around. What you know ? I know that . I would be wanting your knowledge when I find a thing to ask. I am not underestimating you . I am sure most of you are better and older than me . But how can you understand that I cant use fgets function by my fgets(blablslnbla) writing. Are you all this hardworking that does not mind to write long sentences when answering a simple question? And also I had a look at FAQ. Yes there are lot of useful things. But that is not that gets thing. A real beginner that knew about strings for a hour would know that. That's what I did.And ZACS find another things for answering people's questions. All you do is telling people see FAQ blblsalblablba... Did you write those , coz I think you have sensual relationship with those lines. Sorryh for overreacting again. But you know what you could answer me this zacs:

    Code:
    FILE *fp;
    fp=fopen("d.txt","w");
    char k;
    k=getchar();
    while(k!=x) {
    fputc(k,fp);
    k=getchar(); }
    --------
    When inputing the chars if I write "car" text file becomes this:

    car

    But if I input it like "c return a return r return" It becomes
    c
    a
    r

    Yea I see enter is the '\n' ,but strings doenst get enter as a \n . But how can File pointers can do that?

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by ozumsafa View Post
    Sorry for overreacting , I am just trying to tell you , I am not a kid here messing around. What you know ? I know that . I would be wanting your knowledge when I find a thing to ask. I am not underestimating you . I am sure most of you are better and older than me . But how can you understand that I cant use fgets function by my fgets(blablslnbla) writing. Are you all this hardworking that does not mind to write long sentences when answering a simple question? And also I had a look at FAQ. Yes there are lot of useful things. But that is not that gets thing. A real beginner that knew about strings for a hour would know that. That's what I did.And ZACS find another things for answering people's questions. All you do is telling people see FAQ blblsalblablba... Did you write those , coz I think you have sensual relationship with those lines. Sorryh for overreacting again. But you know what you could answer me this zacs:

    Code:
    FILE *fp;
    fp=fopen("d.txt","w");
    char k;
    k=getchar();
    while(k!=x) {
    fputc(k,fp);
    k=getchar(); }
    --------
    When inputing the chars if I write "car" text file becomes this:

    car

    But if I input it like "c return a return r return" It becomes
    c
    a
    r

    Yea I see enter is the '\n' ,but strings doenst get enter as a \n . But how can File pointers can do that?
    1. The FAQ is there for a reason
    2. gets is depreciated, use fgets
    3. Don't use gets because it's easier to write, that's a stupid excuse.

    And for your code, providing your not being a smart ass or sarcastic.
    1. Where does 'x' come from?
    2. Disregarding x, if you write 'car' and push enter, the stream (stdin in this case) holds 'car\n', therefore the loop will continue (not asking for input) until it's all written to the file. Similar with 'c return a return...'
    The stream will hold:
    'c\n', then 'a\n' then 'r\n'.
    See the FAQ regarding user input.

  9. #9
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    I didnt write all the things and I forgot to add 'x' .That is not a variable . I want user to write x end of the lne
    like this
    carx
    or like this
    c
    a
    r
    x

    One writes "car" one writes :
    c
    a
    r

    I didnt read all you wrote sorry I gotta go

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,751
    > so when you are executing the program repeatedly lines dont play hard to change !! Goddd.

    I'm sorry, what was that? fgets has no affect on repeated execution anymore than gets does, except that when gets tries to read everything the program explodes. If you even run into a situation where repeated execution even matters, it's bad news bears. Goddd.

    But this has been argued by people smarter than us. I do agree that everyone should chill out now. Points made. Thread over.

  11. #11
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    citizen , like everybody else , you did not even get one of the points I have made. And are you talking about smartness? Stop there , you can not know who is smarter than who. And you have no right to question my intelligence ,furthermore I am sure I have nothing to talk about it with you ; because I have seen all the education you get in US and other foreign countries.You take the courses on your 18 when we take them at our 13-14 . So shut your business here and go away . And I am tired of this topic , OFCOURSE FGETS IS BETTER THEN GETS. I MEAN THERE , I WAS TRYING TO POST A QUESTION QUICKLY SOOO ; GETS(S) IS SOOOO MUCH SHORTER THAN FGETS(S,N,STDIN) I WROTE IT as GETSS?? SO WHAT ???ARE YOU HAVING A PLEASURE TO CLARIFY YOUR QUESTIONABLE WISDOM TO PEOPLE?? THE TOPIC IS DONE I JUST WANT ZAC TO ANSWER MY CAR THING.NOT BECAUSE I AM QUESTIONING HIS KNOWLEDGE ; I WONDER THAT , AND RIGHT NOW I DONT WANT TO LOSE TIME . BECAUSE I GOTTA FILL A DAMN SULPHAMATE BATH!

  12. #12
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    Ahh , also I do not need the ANSWER zac will do . cOZ I saw the reason.You should learn that posting posting and posting with your empty answering pleasure does not mean anything and I really wonder are you in university or something , how old are you , what do you do for life ?

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,115
    I have moved the gets() specific discussion away from the other thread so StrikeMech can get a better response later.

    ozumsafa, the FAQ clearly states that gets() is unsafe. That appears to be the consensus among the community here, and from what I see that is correct. You are free to use it in your own code, of course, but kindly refrain from suggesting it to others on this message board.

    If you want to pose a question, please start a new thread.
    Last edited by laserlight; 07-19-2007 at 05:19 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,751
    > Stop there , you can not know who is smarter than who.

    Right, but I happen to know that other people in other places have had this argument (like the clc newsgroup) and people have made smarter statements in support of gets. They're probably smarter than both of us.

    I suppose the real reason I get involved in threads like this one is because I like to speak up when the heat of the argument has died down a bit. I will admit this isn't a perfect place, but I have noticed that you've taken things very personally which doesn't work well anywhere. Zach put it rather bluntly, but stop apologizing, it's fine: understand that people here help others as part of a team effort - let them say what they want to.

    If you want to be bothered less by corrections, be right, and only post code after it's safe to use. Hope that helps.

  15. #15
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Zach put it rather bluntly, but stop apologizing, it's fine: understand that people here help others as part of a team effort - let them say what they want to.
    I put it bluntly due to his stubbornness on the other post, I apologize. Although I don't think that constitutes his rudeness. The boards are about helping, not raging it at each other.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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