string to integer to double
Converts a numeric string to integer and then to double. Demonstrates the use of atoi() and atof().
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
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;
}
Upload
Original Comments (3)
Recovered from Wayback Machine