C - gets() function implementation help

This is a discussion on C - gets() function implementation help within the C Programming forums, part of the General Programming Boards category; Hi everyone, I am a newbie in C programming. I have to make an implementation of gets() function from stdio.h, ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    C - gets() function implementation help

    Hi everyone,

    I am a newbie in C programming.
    I have to make an implementation of gets() function from stdio.h, but I am not sure where to start.

    Please advice, any help is welcome.

    Thank you,
    Brian.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Use getchar() and a loop.

    Though modelling fgets() would be a better idea.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    Quote Originally Posted by Salem View Post
    Use getchar() and a loop.

    Though modelling fgets() would be a better idea.
    Thanks for advice, but I think should try to do it without using stdio.h - is that possible?

    You mean fgets is a safer function?

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    fgets() is indeed better. I don't know what you meant by not using stdio.h . I would actually be interested in seeing that.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by prakakat View Post
    Thanks for advice, but I think should try to do it without using stdio.h - is that possible?
    Nah. std is for standard, io is for input/output. C all by itself does not include this, so without stdio.h you cannot access any input, and you cannot produce any output.

    Programs which do not include stdio are possible, but beyond just clocking time on the processor they don't have any purpose.

    ifaTreeFallsintheForest.c
    Code:
    int main() {
         int i = 100;
         char buffer[] = "can you hear me now?";
         while (i > 0) {
               [ do things with variables ]
    Last edited by MK27; 04-10-2010 at 01:12 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 11:08 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

Tags for this Thread


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