Lushous
asked on
Word Generator
I need to develop a program which will ask the user to enter a seven digit phone number and then based on this number display all the possible word generated out comes.However, not including 0 and 1.
Eg. digit 2 gives the letters A B C.
What Im not sure about 100% is how I should change the numbers to alphabet corresponding numbers.
I am not particularly strong in C but have developed some code and so forth but it seems to have some problems.
Eg. digit 2 gives the letters A B C.
What Im not sure about 100% is how I should change the numbers to alphabet corresponding numbers.
I am not particularly strong in C but have developed some code and so forth but it seems to have some problems.
ASKER
Edited text of question.
ASKER
Edited text of question.
do you have any algorithm for the conversion ? any written stuff on how to convert ?
Arnon David.
Arnon David.
ASKER
Arnon, im converting using a switch statement and then the following as my cases -
case '2':
alph[idx] = 'A';
gen_alpha(num, alph, (idx+1) );
alph[idx] = 'B';
gen_alpha(num, alph, (idx+1) );
alph[idx] = 'C';
gen_alpha(num, alph, (idx+1) );
break;
And so on until I reach the number nine and its correspondants.
case '2':
alph[idx] = 'A';
gen_alpha(num, alph, (idx+1) );
alph[idx] = 'B';
gen_alpha(num, alph, (idx+1) );
alph[idx] = 'C';
gen_alpha(num, alph, (idx+1) );
break;
And so on until I reach the number nine and its correspondants.
Sorry I still not understand the connection between 2 and A B C.
What should be the output for 3?
What should be the output for 3?
ASKER
Ok, well basically I have it all planned Im just not to strong in C and unsure as I cant get this to work yet.
For 3 I would follow with the digits: D, E, F
Then for 4: G, H ,I
And so on except that I skip the letter Q along the way.
For 3 I would follow with the digits: D, E, F
Then for 4: G, H ,I
And so on except that I skip the letter Q along the way.
i don't understad it either. please give a few more examples for input\output.
Arnon David.
Arnon David.
ASKER
*I know what you mean, I dont quite get it myself. Basically one of the ohter experts has been helping me and said that that code would work. However, I am having problems understanding it.
Basically I ask the user to enter a seven digit number and then based on the numbers within the entered number I display all the possible alphabetical outcomes.
Eg. plumber - 7586637
The above code Im not sure how it works but obviously it says that for number 2 the letters which correspond to it are A,B,C
For number 3 the letters corresponding are D, E,F
And so follows until we reach number nine which is the last number in the set and also the last alphabet letters, W, X, Y.
Basically I ask the user to enter a seven digit number and then based on the numbers within the entered number I display all the possible alphabetical outcomes.
Eg. plumber - 7586637
The above code Im not sure how it works but obviously it says that for number 2 the letters which correspond to it are A,B,C
For number 3 the letters corresponding are D, E,F
And so follows until we reach number nine which is the last number in the set and also the last alphabet letters, W, X, Y.
Oh you are talking about the chars on a telephon pad.
2=ABC
3=DEF
4=GHI
5=JKL
6=MN
7=PRS
8=TUV
9=WXY
0=OQZ
So try This code
char *keys[10]={"OQZ","","ABC", "DEF","GHI ","JKL","M N","PRS"," TUV","WXY" };
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep th]]);i++) {
key[depth]=keys[num[depth] ][i];
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
2=ABC
3=DEF
4=GHI
5=JKL
6=MN
7=PRS
8=TUV
9=WXY
0=OQZ
So try This code
char *keys[10]={"OQZ","","ABC",
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep
key[depth]=keys[num[depth]
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
To start use
char key[10];
make_key ("26082",key,0);
char key[10];
make_key ("26082",key,0);
ASKER
Thats quite good rbr. Without asking too much would it be possible for you to comment this code so I know whats happening and why and where etc.
That way I also know what I need to add.
I appreciate all your help!
That way I also know what I need to add.
I appreciate all your help!
ASKER
The keys should be -
2 ABC
3 DEF
4 GHI
5 JKL
6 MNO
7 PRS
8 TUV
9 WXY
2 ABC
3 DEF
4 GHI
5 JKL
6 MNO
7 PRS
8 TUV
9 WXY
char *keys[10]={"","","ABC","DE
/* These are the keys
pos 0 = "" no key
pos 1 = "" no key
pos 2 = "ABC"
..
..
..
*/
void make_key (char *num, char *key, int depth)
/* num string of the number you want to convert
* key current key generated
* depth depth of the generation
*/
{
int i;
for (i=0;i<strlen(keys[num[dep
key[depth]=keys[num[depth]
/* Place i. char of key reprensentation of num at pos depth to to key */
if (depth < strlen (num)+1) {
/* Not finished. Go one position further */ make_key (num,key,depth+1);
} else {
/* finished. Terminate the key and print it */ key[depth+1]=0;
printf ("%s\n",key);
}
}
ASKER
Thanks alot rbr for writing in the comments it is a little clearer to me now.I appreciate all your help.
However, without running this I assume that this code will work for just just one digit at a time..??
And thus I need to repeat this code another six times?????
Or will this do the job for the whole program??
However, without running this I assume that this code will work for just just one digit at a time..??
And thus I need to repeat this code another six times?????
Or will this do the job for the whole program??
ASKER
Oh, and I noticed that above there is a commenmt from you rbr that tells me to start use
char key[10];
make_key ("26082",key,0);
what does this mean?? Do i still need to use this?? What is this for???
Thanks!
char key[10];
make_key ("26082",key,0);
what does this mean?? Do i still need to use this?? What is this for???
Thanks!
ASKER
I have been playing wioth this program all day but cant get it to work!!!!!!!
ASKER
rbr could you help me I have the following program done but its not working-
#include <stdio.h>
#include <string.h>
// Required for string function
// Function Declarations
void make_key (char *num, char *key, int depth);
// num string of the number you want to convert key current key generated dep
main()
{
//Variable initalistaion for numbers
char *keys[10]={"","","ABC","DE F","GHI"," JKL","MNO" ,"PRS","TU V","WXY"};
int i, num;
printf("Please enter a seven digit telephone number: \n");
scanf("%d", &num);
for (i = 0; i < strlen(keys[num[depth]]); i++) {
key[depth]=keys[num[depth] ][i];
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
}
else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
Note - For the output, we should have about 1000 words or so, will this be able to be generated and displayed on the screen?????
#include <stdio.h>
#include <string.h>
// Required for string function
// Function Declarations
void make_key (char *num, char *key, int depth);
// num string of the number you want to convert key current key generated dep
main()
{
//Variable initalistaion for numbers
char *keys[10]={"","","ABC","DE
int i, num;
printf("Please enter a seven digit telephone number: \n");
scanf("%d", &num);
for (i = 0; i < strlen(keys[num[depth]]); i++) {
key[depth]=keys[num[depth]
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
}
else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
Note - For the output, we should have about 1000 words or so, will this be able to be generated and displayed on the screen?????
ASKER
Rbr Ive rejected your answer in the hope that you will be able to help me further, as ive indicated above.
Im knew to this site and noticed that it said that my question was locked so in the event that that would mean that you could not longer see this question ive rejected your answer.
That way you can see that I still needs your help.
However, I know that you've given me the answer and I do intend to accept this later.
Im knew to this site and noticed that it said that my question was locked so in the event that that would mean that you could not longer see this question ive rejected your answer.
That way you can see that I still needs your help.
However, I know that you've given me the answer and I do intend to accept this later.
Sorry I was of work when i got yopur comments.try This
#include <stdio.h>
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE F","GHI"," JKL","MNO" ,"PRS","TU V","WXY"};
/* These are the keys
pos 0 = "" no key
pos 1 = "" no key
pos 2 = "ABC"
..
..
..
*/
int main (int argn, char *argv[])
{
char num[10];
vhar key[10];
int number
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_keys(num,key,0);
return (1);
}
void make_key (char *num, char *key, int depth)
/* num string of the number you want to convert
* key current key generated
* depth depth of the generation
*/
{
int i;
for (i=0;i<strlen(keys[num[dep th]]);i++) {
key[depth]=keys[num[depth] ][i];
/* Place i. char of key reprensentation of num at pos depth to to key */
if (depth < strlen (num)+1) {
/* Not finished. Go one position further */ make_key (num,key,depth+1);
} else {
/* finished. Terminate the key and print it */ key[depth+1]=0;
printf ("%s\n",key);
}
}
if you enter 2 the output should be
A
B
C
if you enter 23 the output should be
AD
AE
AF
BD
BE
BF
CD
CE
CF
#include <stdio.h>
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE
/* These are the keys
pos 0 = "" no key
pos 1 = "" no key
pos 2 = "ABC"
..
..
..
*/
int main (int argn, char *argv[])
{
char num[10];
vhar key[10];
int number
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_keys(num,key,0);
return (1);
}
void make_key (char *num, char *key, int depth)
/* num string of the number you want to convert
* key current key generated
* depth depth of the generation
*/
{
int i;
for (i=0;i<strlen(keys[num[dep
key[depth]=keys[num[depth]
/* Place i. char of key reprensentation of num at pos depth to to key */
if (depth < strlen (num)+1) {
/* Not finished. Go one position further */ make_key (num,key,depth+1);
} else {
/* finished. Terminate the key and print it */ key[depth+1]=0;
printf ("%s\n",key);
}
}
if you enter 2 the output should be
A
B
C
if you enter 23 the output should be
AD
AE
AF
BD
BE
BF
CD
CE
CF
Sorry I was of work when i got yopur comments.try This
#include <stdio.h>
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE F","GHI"," JKL","MNO" ,"PRS","TU V","WXY"};
/* These are the keys
pos 0 = "" no key
pos 1 = "" no key
pos 2 = "ABC"
..
..
..
*/
int main (int argn, char *argv[])
{
char num[10];
vhar key[10];
int number
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_keys(num,key,0);
return (1);
}
void make_key (char *num, char *key, int depth)
/* num string of the number you want to convert
* key current key generated
* depth depth of the generation
*/
{
int i;
for (i=0;i<strlen(keys[num[dep th]]);i++) {
key[depth]=keys[num[depth] ][i];
/* Place i. char of key reprensentation of num at pos depth to to key */
if (depth < strlen (num)+1) {
/* Not finished. Go one position further */ make_key (num,key,depth+1);
} else {
/* finished. Terminate the key and print it */ key[depth+1]=0;
printf ("%s\n",key);
}
}
if you enter 2 the output should be
A
B
C
if you enter 23 the output should be
AD
AE
AF
BD
BE
BF
CD
CE
CF
#include <stdio.h>
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE
/* These are the keys
pos 0 = "" no key
pos 1 = "" no key
pos 2 = "ABC"
..
..
..
*/
int main (int argn, char *argv[])
{
char num[10];
vhar key[10];
int number
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_keys(num,key,0);
return (1);
}
void make_key (char *num, char *key, int depth)
/* num string of the number you want to convert
* key current key generated
* depth depth of the generation
*/
{
int i;
for (i=0;i<strlen(keys[num[dep
key[depth]=keys[num[depth]
/* Place i. char of key reprensentation of num at pos depth to to key */
if (depth < strlen (num)+1) {
/* Not finished. Go one position further */ make_key (num,key,depth+1);
} else {
/* finished. Terminate the key and print it */ key[depth+1]=0;
printf ("%s\n",key);
}
}
if you enter 2 the output should be
A
B
C
if you enter 23 the output should be
AD
AE
AF
BD
BE
BF
CD
CE
CF
#include <stdio.h>
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE F","GHI"," JKL","MNO" ,"PRS","TU V","WXY"};
int main (int argn, char *argv[])
{
char num[10];
char key[10];
int number;
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_keys(num,key,0);
return (1);
}
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep th]]);i++) {
key[depth]=keys[num[depth] ][i];
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
Copy and paste didnt work, sorry.
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE
int main (int argn, char *argv[])
{
char num[10];
char key[10];
int number;
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_keys(num,key,0);
return (1);
}
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep
key[depth]=keys[num[depth]
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
Copy and paste didnt work, sorry.
ASKER
Unfortunately Ive tried and tried but i cant get this to work! I have ran in and basically i get it to "enter number" it then allows me to enter the number but then terminates!!!!!
I am running it/editing etc in the Microsoft Visual C++ software.
Do you know what the cause of this is?? Also, could you explain to me why you do some things?? I have only really done the basics in C before and I havnt learbt some of the code below and was wondering if you could explain to me.I have put comments in capitals where i dont understand -
#include <stdio.h>
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE F","GHI"," JKL","MNO" ,"PRS","TU V","WXY"};
int main (int argn, char *argv[]) //WHY DO YOU USE INT MAIN THEN THOSE ARGUMENTS??WHAT DOES IT DO? HOW COME WE DONT USE THE NORMAL PLAIN MAIN??
{
char num[10];
char key[10];
int number;
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number); /*WHY SPRINTF HERE
make_keys(num,key,0);
return (1); /*WHY DO YOU USE THE (1) HERE?? WHAT DOES IT DO?
}
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep th]]);i++) {
key[depth]=keys[num[depth] ][i];
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
I am running it/editing etc in the Microsoft Visual C++ software.
Do you know what the cause of this is?? Also, could you explain to me why you do some things?? I have only really done the basics in C before and I havnt learbt some of the code below and was wondering if you could explain to me.I have put comments in capitals where i dont understand -
#include <stdio.h>
#include <string.h>
void make_key (char *num, char *key, int depth);
char *keys[10]={"","","ABC","DE
int main (int argn, char *argv[]) //WHY DO YOU USE INT MAIN THEN THOSE ARGUMENTS??WHAT DOES IT DO? HOW COME WE DONT USE THE NORMAL PLAIN MAIN??
{
char num[10];
char key[10];
int number;
printf ("Enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number); /*WHY SPRINTF HERE
make_keys(num,key,0);
return (1); /*WHY DO YOU USE THE (1) HERE?? WHAT DOES IT DO?
}
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep
key[depth]=keys[num[depth]
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
rbr,
pardon me if u'm wrong, but there seems to be a slight prob... i haven't run the code but anyway, shouldn't u minus ascii for '0' b4 referencing keys? cos num is a char array that contains eg. "12345"?
pardon me if u'm wrong, but there seems to be a slight prob... i haven't run the code but anyway, shouldn't u minus ascii for '0' b4 referencing keys? cos num is a char array that contains eg. "12345"?
Thx lychee. Yes that is the error.
for (i=0;i<strlen(keys[num[dep th]]);i++) {
should be
for (i=0;i<strlen(keys[num[dep th]-`0`]); i++) {
and
key[depth]=keys[num[depth] ][i];
should be
key[depth]=keys[num[depth] -`0`][i];
for (i=0;i<strlen(keys[num[dep
should be
for (i=0;i<strlen(keys[num[dep
and
key[depth]=keys[num[depth]
should be
key[depth]=keys[num[depth]
I wrote the code first for integers and after this I change it to characters.
return (1)
main is a int procedure. So you should return somethink to the OS. Is good for error checking.
main is a int procedure. So you should return somethink to the OS. Is good for error checking.
int argn;
char *argv[];
argn is are the numbers od argumets passed to the function + 1 since the program name itself is one argument
*argv[] is a pointer field where these arguments are stored.
Read the C-Faqs at
http://www.eskimo.com/~scs/C-faq/top.html
char *argv[];
argn is are the numbers od argumets passed to the function + 1 since the program name itself is one argument
*argv[] is a pointer field where these arguments are stored.
Read the C-Faqs at
http://www.eskimo.com/~scs/C-faq/top.html
ASKER
Thanks rbr, but i now have errors I have never come across before??? What do i do??? This is how I now have the program...
#include <stdio.h>
#include <string.h>
// Function Declarations
void make_key (char *num, char *key, int depth); // num string of the number you want to convert key current key generated depth
char *keys[10]={"","","ABC","DE F","GHI"," JKL","MNO" ,"PRS","TU V","WXY"}; //initalisation of the keys
int main (int argn, char *argv[])
{
char num[10];
char key[10];
int number;
instructions (); //Displays instructions
printf (" enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_key(num,key,0);
return (1);
}
//Function for Make Key ()
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep th]-`0`]); i++) {
key[depth]=keys[num[depth] -`0`][i];
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
#include <stdio.h>
#include <string.h>
// Function Declarations
void make_key (char *num, char *key, int depth); // num string of the number you want to convert key current key generated depth
char *keys[10]={"","","ABC","DE
int main (int argn, char *argv[])
{
char num[10];
char key[10];
int number;
instructions (); //Displays instructions
printf (" enter number ?");
scanf ("%d",&number);
sprintf (num,"%d",number);
make_key(num,key,0);
return (1);
}
//Function for Make Key ()
void make_key (char *num, char *key, int depth)
{
int i;
for (i=0;i<strlen(keys[num[dep
key[depth]=keys[num[depth]
if (depth < strlen (num)+1) {
make_key (num,key,depth+1);
} else {
key[depth+1]=0;
printf ("%s\n",key);
}
}
}
ASKER
The errors that come up now are -2x "unknown character 0x60"
2x "<: signed/unsigned mismatch"
2x "<: signed/unsigned mismatch"
check
the ´ ´ in the 2 lines where . If you have done copy and paste the could be coneverted through the net.
You can use 48 instead of ´0´ too.
in which line does the signed/usigned error occur?
btw: Do you know anythink about C. These errors are very basic.
the ´ ´ in the 2 lines where . If you have done copy and paste the could be coneverted through the net.
You can use 48 instead of ´0´ too.
in which line does the signed/usigned error occur?
btw: Do you know anythink about C. These errors are very basic.
Maybe you have a very strong error checking. Then change the line
for (i=0;i<strlen(keys[num[dep th]-`0`]); i++)
to
for (i=0;i<(int)strlen(keys[nu m[depth]-` 0`]);i++)
and
if (depth < strlen (num)+1) {
to
if (depth <(int)( strlen (num)+1)) {
for (i=0;i<strlen(keys[num[dep
to
for (i=0;i<(int)strlen(keys[nu
and
if (depth < strlen (num)+1) {
to
if (depth <(int)( strlen (num)+1)) {
ASKER
I dont know a tremendous lot unfortunately. Im still trying to pick things up and learn.
Thank for the above, the only thing is that nothing prints out......????
Im so sorry.
Thank for the above, the only thing is that nothing prints out......????
Im so sorry.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much for all your help with this program! I appreciate it!!!!
Thank you for all your patience with me too.I hope one day i can return the favour.
Thank you for all your patience with me too.I hope one day i can return the favour.
Arnon David.
P.S., if this is homework, we here at EE are forbiden to do it for you, we can only help in specific problems you might have.