Thread: gets and puts does'nt work!!

  1. #31
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103

    Maybe my compiler sucks! because when I use every function in my whole code it doesn't work!
    Maybe I'm the problem :lol:
    anyway this function that I wrote solve my problem!

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It doesn't work only because you don't share your code.
    You are a bad influence with your extremely unsafe, non-portable proprietary gets_v2 function.
    Post your code already. Then maybe someone can help you do the right thing. Or you could stop doing C altogether. C is not a playground. I repeat: C is NOT a playground. It's an advanced language which sacrifices safety for speed.
    Unless you KNOW what you're doing, you shouldn't be using C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    can you forget it!
    I apologize to all for my bad words.
    I didn't need help anymore about this issue
    PLEASE FORGIVE ME

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, I don't think it's in me to forgive someone who uses a function that's worse than gets().
    Sorry.
    (Can still help you correct that, however.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #35
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    Quote Originally Posted by Elysia View Post
    No, I don't think it's in me to forgive someone who uses a function that's worse than gets().
    Sorry.
    (Can still help you correct that, however.)
    ok, the problem is that I don't know what buffer is, cause I didn't learn it yet. and function that I wrote is enough for me and my project and my teacher!

    if you're serious to help me help me to solve getstr() function that I wrote

    thanks alot

  6. #36
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by behzad_shabani View Post
    and function that I wrote is enough for me and my project and my teacher!
    Well, your teacher is stupid (no offence to you).

    if you're serious to help me help me to solve getstr() function that I wrote
    There's no point, really. Anything you write will be unportable.
    Instead, just use fgets.

    If you have this:
    Code:
    char buf[50];
    gets(buf);
    Then this translates into (using fgets):
    Code:
    char buf[50];
    fgets(buf, sizeof(buf), stdin);
    Buffer is basically a storage area in memory where you can store stuff. The variable "buf" here is a buffer of 50 chars where you store the input from the user.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #37
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    Quote Originally Posted by Elysia View Post
    Well, your teacher is stupid (no offence to you).
    Maybe He is but he want everything he taught!



    Quote Originally Posted by Elysia View Post
    If you have this:
    Code:
    char buf[50];
    gets(buf);
    Then this translates into (using fgets):
    Code:
    char buf[50];
    fgets(buf, sizeof(buf), stdin);
    Buffer is basically a storage area in memory where you can store stuff. The variable "buf" here is a buffer of 50 chars where you store the input from the user.
    can I use another variable instead of buf?

  8. #38
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by behzad_shabani View Post
    can I use another variable instead of buf?
    Of course you can. You can name it whatever you want and change the size to whatever you want.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #39
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    But I do it before and it did'nt work

  10. #40
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A thousand things can go wrong in a program, especially with undefined behavior.
    When you get something like that, anything can fail.
    The problem isn't the fgets line, but something else, as many have told you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #41
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    I don't remember what I've wrote, to post here

    but in Turbo C (My Original code) when I trace it, fgets do nothing and next line execute!?

    the same problem for gets. but when I use scanf it worked. but scanf wasn't what I need. so I wrote getstr.

  12. #42
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    Any way thank you very very much!
    You're so kind!
    I learned more about C
    and forgive me for all bad thing I did

  13. #43
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I also suggest you get rid of Turbo C. It's old, deprecated and not standard complaint.
    You will find many other good IDEs here.
    I suggest you upgrade.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #44
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by behzad_shabani View Post
    I don't remember what I've wrote, to post here

    but in Turbo C (My Original code) when I trace it, fgets do nothing and next line execute!?

    the same problem for gets. but when I use scanf it worked. but scanf wasn't what I need. so I wrote getstr.
    As suggesting around post #2, you should not mix scanf with fgets (and equally gets - but you should not use gets at all). The reason you should not do that is that scanf() leaves first unused data in the input buffer. If you enter a number, that usually means a newline.Then fgets() will read data until the first newline - which is the first thing it finds in the input. So you don't get any data read in (other than the newline character itself).

    You can work around this problem by adding a "getchar()" after the scanf() - but scanf is difficult to use anyways - try entereing "abc" when it expects a number, and I can almost certainly say that your program will loop "forever".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #45
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    Quote Originally Posted by Elysia View Post
    I also suggest you get rid of Turbo C. It's old, deprecated and not standard complaint.
    You will find many other good IDEs here.
    I suggest you upgrade.
    thanks

    in iran we use every old thing.
    last year in university taught Pascal :lol:

Popular pages Recent additions subscribe to a feed