VB icon

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: 729
 
     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?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :string to integer to double
//**************************************
#include<stdio.h>
#include<stdlib.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// 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<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;
}


Report Bad Submission
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:

Your Vote

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 ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.