# i'm having trouble to program this!! SOS reply asap

This is a discussion on i'm having trouble to program this!! SOS reply asap within the C# Programming forums, part of the General Programming Boards category; Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with ...

1. ## i'm having trouble to program this!! SOS reply asap

Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them.

Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop eight-letter words that correspond to their phone numbers. For example, a person whose telephone number is 4263-7663 might use the correspondence in Table 1 to develop the eight-letter word “HANDSOME” so that people can easily remember his phone number. Each eight-letter word corresponds to exactly one eight-digit telephone number. A delivery service could surely do so with the number 3354-8379 (i.e. “DELIVERY”).

Each eight-digit phone number corresponds to many separate eight-letter words. Unfortunately, most of these represent unrecognizable juxtapositions of letters. It is possible, however, that the owner of a barber shop would be pleased to know that the shop’s telephone number, 4247-2888, corresponds to “HAIRCUTS”. A hospital with the phone number 4677-4825 would be pleased to know that the number corresponds to the letters “HOSPITAL”. A Bodyshop owner would be pleased to know that the shop’s number, 2639-7467, corresponds to “BODYSHOP”.

Write a program that, given an eight-digit number, writes to a file every possible eight-letter word combination corresponding to that number. There are 6561 (38) such words. Avoid phone numbers with the digits 0 and 1.

Digit Letters
2 A B C
3 D E F
4 G H I
5 J K L
6 M N O
7 P R S
8 T U V
9 W X Y
Table 1: Telephone keypad digits and letters.

Post a version that looks like you tried. We are helping people, we are not the homework assignment dumpster.

3. this is my program..tq... but i think i a bit away from the topic

4. this is where i can go...hehe

5. I have already solved this problem a month ago. I got it from a programming contest site. Lemme look at my files.

6. This was a month ago. ( I have improved since then ( ashamed of this code ) )

Its not exactly the same problem but the method should be the same. My solution was a little messy.

Theres should be a better solution than mine. As this was made by a beginner .

This code counts and prints all the possible combination of the last the four digits in a telephone number.

Code:
```#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>

#define A 65

int main()
{
char *icomb;
int intcomb[4] = { 0 };
char input[20] = { 0 };
int ctr1, ctr2, ctr3, ctr4;
int permutation = 0;
clrscr();

printf( "phone: " );
fgets( input, sizeof( input ), stdin );
icomb = strchr( input, '\n' );
icomb = NULL;
icomb = strchr( input, '-');
icomb = &icomb[1];
printf( "last 4 digit is %s", icomb );

for( ctr1 = 0; ctr1 < 3; ctr1++ ){
for( ctr2 = 0; ctr2 < 3; ctr2++ ){
for( ctr3 = 0; ctr3 < 3; ctr3++ ){
for( ctr4 = 0; ctr4 < 3; ctr4++ ){
printf( "\n%c%c%c%c",
((icomb[0]-48)<2?'0':(((icomb[0]-48)-2)*3)+A+ctr1+0),
((icomb[1]-48)<2?'0':(((icomb[1]-48)-2)*3)+A+ctr2+0),
((icomb[2]-48)<2?'0':(((icomb[2]-48)-2)*3)+A+ctr3+0),
((icomb[3]-48)<2?'0':(((icomb[3]-48)-2)*3)+A+ctr4+0));
permutation++;
if( icomb[3]-48 < 2 ) break;
}
if( icomb[2]-48 < 2 ) break;
}
if( icomb[1]-48 < 2 ) break;
}
if( icomb[0]-48 < 2 ) break;
}

printf( "\n\nTotal Permutation is %d", permutation );

getch();
return 0;
}```

7. thanx for the great code.... but i wan to know whether this code is all in C... only C is allowed in this code..... TQ

8. Yeah its in C. But why did you post this in C# forum?

The code above isnt exactly the same. But itll give give you an idea on how to solve the problem.

9. This assignment, at first, appears to be related to the idea of probability and permutations.

However, consider the main problem with a permutation generator:-

For example, the numeric string '7733428' corresponds to 4*4*3*3*3*3*3 = 3,888 different alpha strings. So that's 3,888 possible words it can be. That means your program has to make up 3,888 possibilities and then check each one against a dictionary file.

You can imagine how many combos would be generated for a string of length 8 -it would certainly cause a lag in your program.

However, if you use your cellphone, the predicative text facility appears to cope with words of eight letters quite comfortably. Why is this?

Well this should tell you that permuation is NOT the answer to this particular problem.

What you should do is to actually convert your dictionary file to it's keypad numeric equivalent.

So for example, convert all the words from a-z to its numerical equivalent.

predict = 7733428
phone = 74663

etc.

Now you have a numeric dictionary file.
All you have to do is check that the number the user entered matchs one of the numbers in your numeric dictionary. Then flag that position and output the word in the ACTUAL dictionary file.

I have already done this. And it is quite easy. This link should give you some ideas on how to convert a string to its numerical keypad equivalent.

http://www.cs.bham.ac.uk/~mdr/teachi.../PredText.html

However, if you wish to explore the idea of permuation generators have a look at this snippet

http://www.cprogramming.com/snippets...ount=30&page=0