Thread: integers to char *

  1. #1
    Unregistered
    Guest

    Question integers to char *

    How do I convert an integer or float to a char *string.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    Here's an example i took from MSDN:

    #include <stdlib.h>
    #include <stdio.h>

    void main( void )
    {
    char *s; double x; int i; long l;

    s = " -2309.12E-15"; /* Test of atof */
    x = atof( s );
    printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );

    s = "7.8912654773d210"; /* Test of atof */
    x = atof( s );
    printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );

    s = " -9885 pigs"; /* Test of atoi */
    i = atoi( s );
    printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );

    s = "98854 dollars"; /* Test of atol */
    l = atol( s );
    printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  2. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM