# Thread: Converting Digits to Words Help!

1. ## Converting Digits to Words Help!

Hello Everyone,

My task is to convert an inputted number i.e. 234567 and print out the words of each digit so it would print "two three four five six seven".

I don't even know where to start. All I know is that i need or should be using switch statements.

Any help will be greatly appreciated. Thanks in advance!

2. If you read in the number as a string str, then the digit '2' is located at str[0].

Code:
```switch(str[0]) {
case '1':  printf("one");
break;
case '2':  printf("two");
break;
...
}```
You should run it in a loop and process each digit in your str.

3. Okay. So I understand what you are talking about and get it, but how do I increment the string?
Thanks.

4. Originally Posted by McZiploc
Okay. So I understand what you are talking about and get it, but how do I increment the string?
Thanks.
You should probably use a for loop. For example if your str is "12345" then you could do something like

Code:
```for (int i=0; i < 5; i++) {
switch(str[i]) {
...
}
}```

5. Okay, thank you again but I have a small problem. I'm trying to put a "-" between the words but having some trouble. Here's my code

Code:
```#include <stdio.h>
#include <strings.h>

int main()
{
char number[255];
int n, digits, x=0, num_length;

printf("Enter a number: ");
scanf("%s", &number);

num_length = strlen(number);

for(n=0; n<=num_length; n++){
switch(number[n]){
case '0': printf("zero");
break;
case '1': printf("one");
break;
case '2': printf("two");
break;
case '3': printf("three");
break;
case '4': printf("four");
break;
case '5': printf("five");
break;
case '6': printf("six");
break;
case '7': printf("seven");
break;
case '8': printf("eight");
break;
case '9': printf("nine");
break;
}
for(x=0; x<=n; x++){
printf("-");
}
}

return 0;
}```

6. Your for loop should probably be:

for (n=0; n < num_length; n++)

Suppose your string is 10 characters. Then the ten characters are number[0], number[1], ..., number[9]

For printing dashes in between, you probably should add something inside your case labels.

Code:
```case '1': printf("one");
printf("-");
break;```

7. Thank you sooo much. Thanks for your time. I finally understand this.