// sprintf() works just like printf() but instead of printing to standard out
// it prints to the given string.
//    see printf.cpp for an example of printf

// sprintf can be uses it to convert numbers to string.

// int sprintf(char *str, const char *format, ...);
//  str is a buffer into which the generated string is placed
//  format is the string that contains the format
//  for example:
//       "My name is %s.  I am %d years old"
//       the %s will be replaced with the first argument
//       the %d will be replaced with the second argument

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{

	double double_value = 42.2;
	int int_value = 42;

	char result[100];
	sprintf(result, "%f", double_value);

	string tmp(result);

	cout << "tmp = " << tmp << endl;


	// NOTE this uses %d not %f
	sprintf(result, "%d", int_value);

	tmp = result;

	cout << "tmp = " << tmp << endl;


}

