function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anarghya
    New Member
    • Oct 2006
    • 18

    function

    write a function in c that accepts a 'float' argument and returns the string
    equivalent of it?
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by anarghya
    write a function in c that accepts a 'float' argument and returns the string equivalent of it?
    Well, I know I can do it, but so I'm not just giving you your homework, how would you start?

    Comment

    • anarghya
      New Member
      • Oct 2006
      • 18

      #3
      please tell me?

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by anarghya
        please tell me?
        Sorry, I'm not going to just give you code - you wouldn't learn it like that. But if you are willing to try it, I will do everything I can to help.

        Comment

        • anarghya
          New Member
          • Oct 2006
          • 18

          #5
          my question is that how i convert a decimal number to coresponding string?

          Comment

          • teddarr
            New Member
            • Oct 2006
            • 143

            #6
            Try writting some pseudocode to get started. Just state in plain language what you think the first few lines of code should do. It'll help you get started.

            Something like:

            prototype definition
            {
            input statement

            conversion expression

            output statement or return statement
            }

            start filling in those phrases with what you want to do and then revise it to code. This technique works for me.
            Last edited by teddarr; Nov 9 '06, 03:00 AM. Reason: add more information

            Comment

            • sivadhas2006
              New Member
              • Nov 2006
              • 142

              #7
              Hi,

              No need to write a functions, I think here is a simple way to do that.

              Code:
              #include <stdlib.h>
              
              #include <stdio.h>
              
              // To convert the number with base 10 to string.
              #define RADIX_VALUE  10
              
              int main()
              {
                 int
                    nTest = 123;
                 char
                    szBuffer[255];
              
                 // To convert the number to string.
                 itoa(nTest, szBuffer, RADIX_VALUE);
              
                 // To print the result.
                 printf(szBuffer);
              
                 return 0;
              }
              Regards,
              M.Sivadhas.

              Comment

              Working...