Thread: what wrong do i make?

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    14

    what wrong do i make?

    char output;
    float sum;
    int N,K;
    sprintf(output,"%f",sum/(N-K));


    [Warning] passing arg 1 of `sprintf' makes pointer from integer without a cast

  2. #2
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    Code:
    char output;
    needs a size.. like

    Code:
    char output[50];
    the error you pasted I don't really get although the compiler I just used does suck....

  3. #3
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    Quote Originally Posted by Sysop_fb
    the error you pasted I don't really get although the compiler I just used does suck....
    "output" is an integer while sptrinf() needs a pointer type.
    Although gcc's (i suppose this ist gcc) error messages are crap sometimes, this one is quite clear imho.

    Btw: Hi board

  4. #4
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    Quote Originally Posted by TactX
    "output" is an integer while sptrinf() needs a pointer type.
    Although gcc's (i suppose this ist gcc) error messages are crap sometimes, this one is quite clear imho.

    Btw: Hi board
    what?
    I don't use gcc

    and sprintf doesn't need a pointer and he didn't declare "output" as an integer.
    You didn't really word yourself very well there..

    Code:
    int sprintf(char *string, char *format, ...)

  5. #5
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    Quote Originally Posted by Sysop_fb
    and sprintf doesn't need a pointer and he didn't declare "output" as an integer.
    You didn't really word yourself very well there..

    Code:
    int sprintf(char *string, char *format, ...)
    What would you call a char* then if not pointer? And a char is an integer type.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by Sysop_fb
    and sprintf doesn't need a pointer and he didn't declare "output" as an integer.
    I think you need to brush up on your data types...You're wrong on both points.
    If you understand what you're doing, you're not learning anything.

  7. #7
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    Well then I'm confused yes...
    char *string is a pointer to a char
    But you can pass it a character array in which case the pointer is set to the character array or pass it a pointer whatever... he said it HAD to be a pointer even though pointers and arrays are very closely tied together in C.

    Okay a char data type belongs to the family of interger data types... but when I see someone say so-and-so is decalred as an integer I think of int instead of some all encompassing integer type, I like being more specific.
    Last edited by Sysop_fb; 10-03-2005 at 02:39 PM.

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    When you pass an array to a function you're passing a pointer to the first element in the array. foo(string) is equivalent to foo(&string[0]) when string is an array if that makes it clearer for you. So even when the original datatype is an array you're still passing a pointer to the function.
    If you understand what you're doing, you're not learning anything.

  9. #9
    Sys.os_type="Unix";;
    Join Date
    Aug 2005
    Posts
    52
    Quote Originally Posted by itsme86
    When you pass an array to a function you're passing a pointer to the first element in the array.
    Didn't know that! Although it makes sense...
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 09:51 PM
  2. make function?
    By D3V1LD0G in forum C Programming
    Replies: 8
    Last Post: 08-21-2008, 11:23 AM
  3. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  4. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 02:16 PM
  5. how to make files
    By quiksilver9531 in forum C++ Programming
    Replies: 6
    Last Post: 02-22-2002, 06:44 PM