0

Can someone please help me with this code, it should change numbersd to text. It compiles but the CMD box has the incorrect output.

#include "stdafx.h"
#include <stdio.h>
#include <string>
//#include <math.h>    // for exp(), pow() and log10()

int _tmain(int argc, _TCHAR* argv[])
{
	int number=5;
	char text[10][10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
	int repeat;
	char *output;

	//Get the number
	//int temp1 = scanf("%d", &number);

	//How many iterations
	//float temp2 = log10(float(number));
	repeat = 1;

	//Generate output
	for (int i=1; i<repeat; i++) {
		int temp3 = number % 10;
		output = text[temp3];// . " " . output;
		number /= 10;
	}

	//Print output
	printf ("%s\n", output);

	return 0;
}
2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by John A
0

Learn about the wonder that is code tags.
http://www.daniweb.com/forums/announcement8-3.html

What are you trying to do here:

output = text[temp3];// . " " . output;

First, if you want to copy the contents of text[temp3], you're going to have to use [search]strcpy[/search]. Secondly, why are you filling 'output' with stuff each iteration and then wiping it out on the next iteration?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.