putc question

This is a discussion on putc question within the C Programming forums, part of the General Programming Boards category; Hello, In this program. When i use puts it works, why putc not work? #include<stdio.h> int main(void) { char buffer[100]; ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    11

    Question putc question

    Hello,

    In this program. When i use puts it works, why
    putc not work?


    #include<stdio.h>

    int main(void)
    {
    char buffer[100];

    printf("Enter an integer\n");
    putc(gets(buffer));

    return 0;
    }

    warning C4003: not enough actual parameters for macro 'putc'
    C:\Windows\Desktop\New Folder\tt1.c(8) : error C2059: syntax error : ')'

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    putc() writes into a file stream only 1 byte at a time specified by you. You are trying to print a whole string instead, which will never work. And more over, where are you trying to write this value? putc() takes two parameters, the first one is the character you want to write and the second one is the FILE *, representing the open file stream where you want to write. In your case, you have not specified the FILE * at all, hence the error.
    You can use fprintf() or fputs() instead, like:
    Code:
    fprnitf(stdout, "%s", gets(buffer));
    fputs(gets(buffer), stdout);
    But beware while using gets(), try to avoid it in all cases. Also, make sure gets() does not return NULL (which you have not handled)

  3. #3
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    >>...But beware while using gets(), try to avoid it in all cases

    Or use fgets()
    it allows you to specify buffer lenght

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 12:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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