# string to integer to double

Email
 Submitted on: 1/6/2015 1:21:00 AM By: Tom Gerhard (from psc cd) Level: Beginner User Rating: By 2 Users Compatibility: C Views: 971

Converts a numeric string to integer and then to double. Demonstrates the use of atoi() and atof().

### INCLUDE files:

Can't Copy and Paste this?
 ```//************************************** //INCLUDE files for :string to integer to double //************************************** #include #include ```
code:
Can't Copy and Paste this?
 ``` //************************************** // Name: string to integer to double // Description:Converts a numeric string to integer and then to double. Demonstrates the use of atoi() and atof(). // By: Tom Gerhard (from psc cd) // // Assumes:Basic but nifty beginner stuff. Hope it is useful to someone. Please vote!! //************************************** #include #include #include int main() { char word[80]; puts("\nEnter an integer string: "); gets(word); /* atoi() : converts its argument, a series of numbers used * as a string, in to an integer value and returns it. The * statement after the conversion statement shows how unsigned * long i has been converted and can now be used. */ unsigned long i = atoi(word); printf("\nThe string '%s' converted to integer is %u.\n", word, i); printf("The converted string squared is %u.\n", i * i); /* atol(): converts its string argument to a double value. The * statement following the conversion shows how it can be used. */ double f = atol(word); printf("\nThe string '%s' converted to double is %.2f.\n", word, f); printf("The converted string divided by 3 is %.3f.\n\n", f / 3); /* play and enjoy! */ system("PAUSE"); return 0; }```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)