Thread: strcpy get errors

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    OK so if you really want here's the GETS macro to behave like gets but in a somewhat safe way:

    Code:
    #define GETS(buf) do { \
         _Static_assert(sizeof buf > sizeof(void*), "GETS(buf): character array required"); \
        fgets(buf, sizeof(buf), stdin); \
         if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0'; \
    } while(0)
    Usage:
    Code:
    printf("type some foo: ");
    char line[20];
    GETS(line);
    printf("your foo was: %s\n", line);
    Last edited by c99tutorial; 01-16-2013 at 05:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using strcpy
    By laxkrzy in forum C Programming
    Replies: 1
    Last Post: 11-15-2010, 11:09 PM
  2. Replies: 1
    Last Post: 06-19-2010, 07:42 AM
  3. What's up with this strcpy?
    By fanoliv in forum C Programming
    Replies: 7
    Last Post: 06-19-2006, 05:24 PM
  4. strcpy
    By Tibo in forum C Programming
    Replies: 2
    Last Post: 03-27-2003, 07:02 AM
  5. strcpy
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 08-01-2002, 01:39 PM