Re: A92: Letters and Numbers


[Prev][Next][Index][Thread]

Re: A92: Letters and Numbers




>l'm getting problems with the DrawStr function.  my compiler says that 
>"passing arg 3...makes a pointer from an interger without a cast."  And so 
>DrawStr doesn't print anything.  What's the problem?

Here's revised code.

  _main()
  {
       char str[14];
       int num = 245;

      sprintf(str,"%d",num);
      DrawStr(0,0,str,4);
  };

Note that "num" has been changed to "str" in the DrawStr call.  Also, you
may have to pass it as an address (use &str instead).  Not sure.


>Also, what does making the str[14] array do?  and how is that a part of 
>sprintf( ?  Thanks!

In C, a string (i.e. one or more characters of text) is represented as an
array of char types (characters).  Defining "char str[14]" creates a
14-character array--that is, a 14-character string.  The function sprintf
formats one or more arguments into a string (in this case, it formats a
decimal number into it).  So the number in "num" gets turned into a string
and placed in "str".
--Cliff Biffle





References: