quick help

This is a discussion on quick help within the C Programming forums, part of the General Programming Boards category; Is there a way to type cast the first argument of these functions ? fputs(const *char, FILE *) fgets(const *char, ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    28

    quick help

    Is there a way to type cast the first argument of these functions ?

    fputs(const *char, FILE *)

    fgets(const *char, FILE *)


    thanks in advance

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I'm not sure exactly what you are asking but I'll give it a go anyway. You can do this:
    Code:
    int break_your_program;
    
    fgets((char *)&break_your_program, stdin);
    //or something similar to this
    But it is more likely in the real world that you would be doing something more like this:
    Code:
    long could_break_your_program = ('%' << 24) | ('l' << 16) | ('d' << 8);
    
    fgets((char *)&could_break_your_program, stdin);
    However, I still would question why someone would even do the second one.

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    1.) Type cast to what? If another 'const' type, it's fine.
    2.) I doubt fgets()'s first argument is of the type specified [Talking about the standard stdio.h - fgets()]

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    fgets has 3 parameters as well
    char *fgets(char *s, size_t n, FILE *stream);

    All the const means in the fputs case is that it tells you that fputs will not modify what you pass to it. It does not mean that what you pass to it has to be const in the first place

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  2. recursive quick sort - stack overflow
    By Micko in forum C Programming
    Replies: 9
    Last Post: 01-01-2005, 04:51 PM
  3. Questions on basic Quick Sort
    By Weng in forum C++ Programming
    Replies: 4
    Last Post: 12-16-2003, 09:06 AM
  4. Quick Sort Help
    By NavyBlue in forum C Programming
    Replies: 1
    Last Post: 03-02-2003, 09:34 PM
  5. Replies: 0
    Last Post: 04-30-2002, 07:24 PM

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