Need help with Arrays: Specific program question
Author Message
Need help with Arrays: Specific program question

Hey guys. I'm hoping someone out there has the patience to help me out in
figuring out this array problem. First off, I'll start out by describing the
program I'm working on. I have to write a program to determine all of the
possible words that can be made from a 7 digit telephone number. The output
would look like this:

So far, I understand how the array counter works. I believe what I must
first decalre a two dimensional array with the first being the phone
number's digit (0-9) and the second being the 3 letters per digit (0,1,2).
Then what I do is make a counter for the 7-digit phone number with 7 nested
for loops, ie...

#define M 10
#define N 3

int a[M][N], i, j, k,....;

int main(void)
{
for (i=0; i<M; ++i)
for (j=0; j<N; ++j)
for (k=0; k<N; ++k)
\* 5 more times with 5 other variables

What I don't understand is a few things. First, for each digit, I need to
store 3 letters (the first being digit 2 = "ABC"). How do I store this? Is
it 'char a[M][N] = {{000, 111, ABC, DEF, GHI, JKL, MNO, PRS, TUV, WXY},{0,
1, 2}}?" And then when the program is going through the 7 cycle count, how
does it know to do A first, then B, then C and so on for each digit? Lastly,
how do I get this to output correctly? I'm guessing the printf statement
will go under the last 'for' statement but how do I format it? Is it
'printf("%c%c%c-%c%c%c%c", j, k, l, m, n, o, p)'? I hope I'm in the right
track and that someone can understand the problem I'm having. If you need me
to clarify more, please let me know. I will greatly appreciate any helpful
tips. Thanks!

Mach278

Sun, 22 Aug 2004 13:02:38 GMT
Need help with Arrays: Specific program question

Quote:
> Hey guys. I'm hoping someone out there has the patience to help me out in
> figuring out this array problem. First off, I'll start out by describing
the
> program I'm working on. I have to write a program to determine all of the
> possible words that can be made from a 7 digit telephone number. The
output
> would look like this:

> So far, I understand how the array counter works. I believe what I must
> first decalre a two dimensional array with the first being the phone
> number's digit (0-9) and the second being the 3 letters per digit (0,1,2).
> Then what I do is make a counter for the 7-digit phone number with 7
nested
> for loops, ie...

> #define M 10
> #define N 3

> int a[M][N], i, j, k,....;

> int main(void)
> {
> for (i=0; i<M; ++i)
>     for (j=0; j<N; ++j)
>         for (k=0; k<N; ++k)
>             \* 5 more times with 5 other variables

> What I don't understand is a few things. First, for each digit, I need to
> store 3 letters (the first being digit 2 = "ABC"). How do I store this? Is
> it 'char a[M][N] = {{000, 111, ABC, DEF, GHI, JKL, MNO, PRS, TUV, WXY},{0,
> 1, 2}}?" And then when the program is going through the 7 cycle count, how
> does it know to do A first, then B, then C and so on for each digit?
Lastly,
> how do I get this to output correctly? I'm guessing the printf statement
> will go under the last 'for' statement but how do I format it? Is it
> 'printf("%c%c%c-%c%c%c%c", j, k, l, m, n, o, p)'? I hope I'm in the right
> track and that someone can understand the problem I'm having. If you need
me
> to clarify more, please let me know. I will greatly appreciate any helpful
> tips. Thanks!

> Mach278

How about using the numeric digit as the array
index with the array element being an array of
the corresponding characters?

char phonedigits[][5] =
{
"0"    /* no letters, use the digit */
"1"    /* no letters, use the digit */
"ABC",
"DEF",
"GHI",
"JKL",
"MNO",
"PQRS",
"TUV",
"WXYZ"

Quote:
};

-Mike

Sun, 22 Aug 2004 13:39:48 GMT
Need help with Arrays: Specific program question

Quote:

>Hey guys. I'm hoping someone out there has the patience to help me out in
>figuring out this array problem. First off, I'll start out by describing the
>program I'm working on. I have to write a program to determine all of the
>possible words that can be made from a 7 digit telephone number. The output
>would look like this:

>So far, I understand how the array counter works. I believe what I must
>first decalre a two dimensional array with the first being the phone
>number's digit (0-9) and the second being the 3 letters per digit (0,1,2).
>Then what I do is make a counter for the 7-digit phone number with 7 nested
>for loops, ie...

>#define M 10
>#define N 3

>int a[M][N], i, j, k,....;
snip

>What I don't understand is a few things. First, for each digit, I need to
>store 3 letters (the first being digit 2 = "ABC"). How do I store this? Is
>it 'char a[M][N] = {{000, 111, ABC, DEF, GHI, JKL, MNO, PRS, TUV, WXY},{0,
>1, 2}}?"

You can initialize the array in its definition with
char a[M][N] = {"000", "111", "ABC", ..., "WXY"};
Quote:
>And then when the program is going through the 7 cycle count, how
>does it know to do A first, then B, then C and so on for each digit?

One way would be to have seven nested loops of the form
for (i0 = 0; i1 < 3; i1++)
for (i1 = 0; i2 < 3; i2++) ...
This will generate all 3 to the 7th power (approximately 1800)
possibilities.
Quote:
>Lastly,
>how do I get this to output correctly? I'm guessing the printf statement
>will go under the last 'for' statement but how do I format it? Is it
>'printf("%c%c%c-%c%c%c%c", j, k, l, m, n, o, p)'?

Something like
print(%c%c%c-%c%c%c%c ", a[x[0]][i0], a[x[1]][i1], ..., a[x[6]][i6]);
where int x[7] contains the seven digits of the phone number as
integers.

<<Remove the del for email>>

Mon, 23 Aug 2004 06:08:39 GMT
Need help with Arrays: Specific program question
Thanks for the help so far guys. I've written the program but I'm not
generating the desired results (it's not cycling through all the possible
words). Could you please take a look at it:

#include <stdio.h>
#include <string.h>

#define M 8 /*Phone number's digit
#define N 3 /*Counter for 3 letters per digit

int main(void)
{
char a[M][N]={"ABC","DEF","GHI","JKL","MNO","PRS","TUV","WXY"};
int i, j, k, l, m, n, o, p; /* for loop variables
for (i=0; i<M; i++)
for (j=0; j<N; j++)
for (k=0; j<N; j++)
for (l=0; l<N; l++)
for (m=0; m<N; m++)
for (n=0; n<N; n++)
for (o=0; o<N; o++)
for (p=0; p<N; p++)

printf("%c%c%c-%c%c%c%c \n", a[0][j], a[1][k], a[2][l], a[3][m], a[4][n],
a[5][o], a[6][p]);

Quote:
}

In my program, I completely disregarded the 0 and 1 digit (since they are
only numbers and I'm looking for all possible words). I'm not sure if that's
the problem. My other problem is displaying the output. I didn't quite
understand what Barry said:

Quote:
>>printf(%c%c%c-%c%c%c%c ", a[x[0]][i0], a[x[1]][i1], ..., a[x[6]][i6]);
>>where int x[7] contains the seven digits of the phone number as
>>integers.

So maybe that's the problem? Lastly, when I get all 2,187 (3^7) results
printed out, how can I make it so that only 5 numbers display per line?
Again, thanks for all the help!

Mach278

Mon, 23 Aug 2004 08:15:57 GMT
Need help with Arrays: Specific program question

Quote:

>Thanks for the help so far guys. I've written the program but I'm not
>generating the desired results (it's not cycling through all the possible
>words). Could you please take a look at it:

Your code is written to handle only the number 234-5678.  When I run
it on my system, I seem to get all possibilities.  What are you seeing
that makes you think it is not.
Quote:

snip code

>In my program, I completely disregarded the 0 and 1 digit (since they are
>only numbers and I'm looking for all possible words). I'm not sure if that's
>the problem. My other problem is displaying the output. I didn't quite
>understand what Barry said:

>>>printf(%c%c%c-%c%c%c%c ", a[x[0]][i0], a[x[1]][i1], ..., a[x[6]][i6]);
>>>where int x[7] contains the seven digits of the phone number as
>>>integers.

You print a[0][...] as the first character.  a[0] contains only the
three characters found on the 2 key.
Quote:

>So maybe that's the problem? Lastly, when I get all 2,187 (3^7) results
>printed out, how can I make it so that only 5 numbers display per line?
>Again, thanks for all the help!

Change your print to place a space instead of a newline after the
number.  Add a counter that you increment at every print.  When it
gets to 5, print a \n and reset the counter.

<<Remove the del for email>>

Mon, 23 Aug 2004 10:47:13 GMT
Need help with Arrays: Specific program question

Quote:

> Thanks for the help so far guys. I've written the program but I'm not
> generating the desired results (it's not cycling through all the possible
> words). Could you please take a look at it:

> #include <stdio.h>
> #include <string.h>

> #define M 8 /*Phone number's digit
> #define N 3 /*Counter for 3 letters per digit

> int main(void)
> {
>  char a[M][N]={"ABC","DEF","GHI","JKL","MNO","PRS","TUV","WXY"};
>  int i, j, k, l, m, n, o, p; /* for loop variables
>  for (i=0; i<M; i++)
>   for (j=0; j<N; j++)
>    for (k=0; j<N; j++)
>     for (l=0; l<N; l++)
>      for (m=0; m<N; m++)
>       for (n=0; n<N; n++)
>        for (o=0; o<N; o++)
>         for (p=0; p<N; p++)

>  printf("%c%c%c-%c%c%c%c \n", a[0][j], a[1][k], a[2][l], a[3][m], a[4][n],
> a[5][o], a[6][p]);

> }

> In my program, I completely disregarded the 0 and 1 digit (since they are
> only numbers and I'm looking for all possible words). I'm not sure if that's
> the problem. My other problem is displaying the output. I didn't quite
> understand what Barry said:

Try this:

Quote:
> #include <stdio.h>

> #define M 8 /* Phone number's digit */
> #define N 3 /* Counter for 3 letters per digit */

> int main(void)
> {
>   char a[M][N]={"ABC","DEF","GHI","JKL","MNO","PRS","TUV","WXY"};
>   int i, j, k, l, m, n, o, p; /* for loop variables */

int col;

col = 0;

Quote:
>   for (i = 0; i < M; i++)
>     for (j = 0; j < N; j++)
>       for (k = 0; j < N; j++)
>         for (l = 0; l < N; l++)
>           for (m = 0; m < N; m++)
>             for (n = 0; n < N; n++)
>               for (o = 0; o < N; o++)
>                 for (p = 0; p < N; p++) {
>                   printf("%c%c%c-%c%c%c%c ",
>                           a[0][j], a[1][k], a[2][l],
>                           a[3][m], a[4][n], a[5][o], a[6][p]);

col++;
if (col >= 8) {
col = 0;
printf("\n");
}

Quote:
>                 }
return 0;
> }

Note that you are allowed to use blanks in the source to make it
legible, and to indent by more than 1 column.  You also do not
have to express a statement in one source line.  Comments work
better when closed, and main returns a value.

Now you work out how to select the right indices at the right
time.  You have some logical failings there.

Hint: for each of 7 positions for each of 8 numbers select 1 of 3
possible letters.

--

Available for consulting/temporary embedded and systems.

Mon, 23 Aug 2004 10:49:26 GMT
Need help with Arrays: Specific program question

Quote:

> Your code is written to handle only the number 234-5678.  When I run
> it on my system, I seem to get all possibilities.  What are you seeing
> that makes you think it is not.

Here is a sample of what I get as an output:

(beginning)
BDI-JOSU
BDI-JOSV
BDI-KMPT
BDI-KMPU
BDI-KMPV
BDI-KMRT
.
.
.
CDI-LOPV
CDI-LORT
CDI-LORU
CDI-LORV
CDI-LOST
CDI-LOSU
CDI-LOSV
(end)

This is clearly not covering the entire range. Shouldn't it go from AAA-AAAA
to ZZZ-ZZZZ?

Quote:
> You print a[0][...] as the first character.  a[0] contains only the
> three characters found on the 2 key.

Ok, I see my mistake now. So based on my code, how should I enter the first
array for the output so that it processes all the letters?

Quote:
> Change your print to place a space instead of a newline after the
> number.  Add a counter that you increment at every print.  When it
> gets to 5, print a \n and reset the counter.

This I get.

Thanks for the help. I'm starting to understand this!

Erasmo

Mon, 23 Aug 2004 11:03:26 GMT
Need help with Arrays: Specific program question

Quote:
> Now you work out how to select the right indices at the right
> time.  You have some logical failings there.

> Hint: for each of 7 positions for each of 8 numbers select 1 of 3
> possible letters.

Ok, I've gone over the tip you provided, trying to figure it out but no
success. The only thing I can think of is have the the first array in the
2-D array be the number of digits (in my case 8) and the second be the
counter for the 3 possible letters. Then what I would do is store the
letters (ie... make digit 1 "ABC", digit 2 "DEF", and so on). But I don't
know if this right and I don't know how to try it out in C-Language. Sorry,
I'm a really bad programmer. I'm very new to all this and am just trying to
get a basic foundation, nothing fancy. Thanks again for the help!

Mach278

Mon, 23 Aug 2004 12:19:25 GMT
Need help with Arrays: Specific program question

Quote:

> Hey guys. I'm hoping someone out there has the patience to
> help me out in
> figuring out this array problem. First off, I'll start out by
> describing the
> program I'm working on. I have to write a program to determine
> all of the
> possible words that can be made from a 7 digit telephone number.
> The output
> would look like this:

> So far, I understand how the array counter works.
> I believe what I must
> first decalre a two dimensional array with the first being the phone
> number's digit (0-9) and the second being the 3 letters per
> digit (0,1,2).
> Then what I do is make a counter for the 7-digit phone number with
> 7 nested
> for loops, ie...

> #define M 10
> #define N 3

> int a[M][N], i, j, k,....;

> int main(void)
> {
> for (i=0; i<M; ++i)
>     for (j=0; j<N; ++j)
>         for (k=0; k<N; ++k)
>             \* 5 more times with 5 other variables

> What I don't understand is a few things. First, for each digit,
> I need to
> store 3 letters (the first being digit 2 = "ABC"). How do I
> store this? Is
> it 'char a[M][N] = {{000, 111, ABC, DEF, GHI, JKL, MNO, PRS,
> TUV, WXY},{0, 1, 2}}?" And then when the program is going through
> the 7 cycle count, how
> does it know to do A first, then B, then C and so on for
> each digit? Lastly,
> how do I get this to output correctly? I'm guessing
> the printf statement
> will go under the last 'for' statement but how do I format it?
> Is it 'printf("%c%c%c-%c%c%c%c", j, k, l, m, n, o, p)'?
> I hope I'm in the right
> track and that someone can understand the problem I'm having.
> If you need me
> to clarify more, please let me know. I will greatly
> tips. Thanks!

> Mach278

/*
** The numbers on the dial have nothing to do with the desired output.
** You should just cycle through letters.
*/

#include <stdio.h>

#define A_Y "ABCDEFGHIJKLMNOPRSTUVWXY"
#define M   (sizeof A_Y - 1)
#define N   7

void letters(int numbers);

int main(void)
{
letters(N);
return 0;

Quote:
}

void letters(int numbers)
{
static int n[N];

for (n[numbers] = 0; n[numbers] != M; ++n[numbers]) {
if (!numbers) {
printf("%c%c%c - %c%c%c%c\n", A_Y[n[6]],
A_Y[n[5]], A_Y[n[4]], A_Y[n[3]],
A_Y[n[2]], A_Y[n[1]], A_Y[n[0]]);
} else {
letters(numbers - 1);
}
}

Quote:
}

--
pete

Mon, 23 Aug 2004 13:14:30 GMT
Need help with Arrays: Specific program question
Nevermind. It seems like I got it to work. I just needed the leading 'for'
loop to be the 7-digit number counter. Thanks again to all those who
replied, you really helped a lot.

Mach278

Mon, 23 Aug 2004 13:21:52 GMT
Need help with Arrays: Specific program question

Wed, 18 Jun 1902 08:00:00 GMT
Need help with Arrays: Specific program question

[snip - formatted]

Quote:
> > I have to write a program to determine all of the possible
> > words that can be made from a 7 digit telephone number. The
> > output would look like this:

> > TAD-DWVR... and so on

[snip]

Quote:
> /*
> ** The numbers on the dial have nothing to do with the desired output.
> ** You should just cycle through letters.
> */

> #include <stdio.h>

> #define A_Y "ABCDEFGHIJKLMNOPRSTUVWXY"
> #define M   (sizeof A_Y - 1)
> #define N   7

> void letters(int numbers);

> int main(void)
> {
>     letters(N);
>     return 0;
> }

> void letters(int numbers)
> {
>     static int n[N];

>     for (n[numbers] = 0; n[numbers] != M; ++n[numbers]) {
>         if (!numbers) {
>             printf("%c%c%c - %c%c%c%c\n", A_Y[n[6]],
>                 A_Y[n[5]], A_Y[n[4]], A_Y[n[3]],
>                 A_Y[n[2]], A_Y[n[1]], A_Y[n[0]]);
>         } else {
>             letters(numbers - 1);
>         }
>     }
> }

I think you missed the point. Output all the possible "words" for a
*given* 7-digit phone number...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define nelem(x)    (sizeof x / sizeof *x)

char *argv0;

char Einvalid[]    = "invalid number";
char Ezeroone[]    = "number cannot contain 0 or 1";

[2] = "abc",
[3] = "def",
[4] = "ghi",
[5] = "jkl",
[6] = "mno",
[7] = "prs",
[8] = "tuv",
[9] = "wxy",

Quote:
};

unsigned int rep[] = {
0x049249, 0x04924a, 0x04924c, 0x049251, 0x049252, 0x049254,
0x049261, 0x049262, 0x049264, 0x049289, 0x04928a, 0x04928c,
0x049291, 0x049292, 0x049294, 0x0492a1, 0x0492a2, 0x0492a4,
0x049309, 0x04930a, 0x04930c, 0x049311, 0x049312, 0x049314,
0x049321, 0x049322, 0x049324, 0x049449, 0x04944a, 0x04944c,
0x049451, 0x049452, 0x049454, 0x049461, 0x049462, 0x049464,
0x049489, 0x04948a, 0x04948c, 0x049491, 0x049492, 0x049494,
0x0494a1, 0x0494a2, 0x0494a4, 0x049509, 0x04950a, 0x04950c,
0x049511, 0x049512, 0x049514, 0x049521, 0x049522, 0x049524,
0x049849, 0x04984a, 0x04984c, 0x049851, 0x049852, 0x049854,
0x049861, 0x049862, 0x049864, 0x049889, 0x04988a, 0x04988c,
0x049891, 0x049892, 0x049894, 0x0498a1, 0x0498a2, 0x0498a4,
0x049909, 0x04990a, 0x04990c, 0x049911, 0x049912, 0x049914,
0x049921, 0x049922, 0x049924, 0x04a249, 0x04a24a, 0x04a24c,
0x04a251, 0x04a252, 0x04a254, 0x04a261, 0x04a262, 0x04a264,
0x04a289, 0x04a28a, 0x04a28c, 0x04a291, 0x04a292, 0x04a294,
0x04a2a1, 0x04a2a2, 0x04a2a4, 0x04a309, 0x04a30a, 0x04a30c,
0x04a311, 0x04a312, 0x04a314, 0x04a321, 0x04a322, 0x04a324,
0x04a449, 0x04a44a, 0x04a44c, 0x04a451, 0x04a452, 0x04a454,
0x04a461, 0x04a462, 0x04a464, 0x04a489, 0x04a48a, 0x04a48c,
0x04a491, 0x04a492, 0x04a494, 0x04a4a1, 0x04a4a2, 0x04a4a4,
0x04a509, 0x04a50a, 0x04a50c, 0x04a511, 0x04a512, 0x04a514,
0x04a521, 0x04a522, 0x04a524, 0x04a849, 0x04a84a, 0x04a84c,
0x04a851, 0x04a852, 0x04a854, 0x04a861, 0x04a862, 0x04a864,
0x04a889, 0x04a88a, 0x04a88c, 0x04a891, 0x04a892, 0x04a894,
0x04a8a1, 0x04a8a2, 0x04a8a4, 0x04a909, 0x04a90a, 0x04a90c,
0x04a911, 0x04a912, 0x04a914, 0x04a921, 0x04a922, 0x04a924,
0x04c249, 0x04c24a, 0x04c24c, 0x04c251, 0x04c252, 0x04c254,
0x04c261, 0x04c262, 0x04c264, 0x04c289, 0x04c28a, 0x04c28c,
0x04c291, 0x04c292, 0x04c294, 0x04c2a1, 0x04c2a2, 0x04c2a4,
0x04c309, 0x04c30a, 0x04c30c, 0x04c311, 0x04c312, 0x04c314,
0x04c321, 0x04c322, 0x04c324, 0x04c449, 0x04c44a, 0x04c44c,
0x04c451, 0x04c452, 0x04c454, 0x04c461, 0x04c462, 0x04c464,
0x04c489, 0x04c48a, 0x04c48c, 0x04c491, 0x04c492, 0x04c494,
0x04c4a1, 0x04c4a2, 0x04c4a4, 0x04c509, 0x04c50a, 0x04c50c,
0x04c511, 0x04c512, 0x04c514, 0x04c521, 0x04c522, 0x04c524,
0x04c849, 0x04c84a, 0x04c84c, 0x04c851, 0x04c852, 0x04c854,
0x04c861, 0x04c862, 0x04c864, 0x04c889, 0x04c88a, 0x04c88c,
0x04c891, 0x04c892, 0x04c894, 0x04c8a1, 0x04c8a2, 0x04c8a4,
0x04c909, 0x04c90a, 0x04c90c, 0x04c911, 0x04c912, 0x04c914,
0x04c921, 0x04c922, 0x04c924, 0x051249, 0x05124a, 0x05124c,
0x051251, 0x051252, 0x051254, 0x051261, 0x051262, 0x051264,
0x051289, 0x05128a, 0x05128c, 0x051291, 0x051292, 0x051294,
0x0512a1, 0x0512a2, 0x0512a4, 0x051309, 0x05130a, 0x05130c,
0x051311, 0x051312, 0x051314, 0x051321, 0x051322, 0x051324,
0x051449, 0x05144a, 0x05144c, 0x051451, 0x051452, 0x051454,
0x051461, 0x051462, 0x051464, 0x051489, 0x05148a, 0x05148c,
0x051491, 0x051492, 0x051494, 0x0514a1, 0x0514a2, 0x0514a4,
0x051509, 0x05150a, 0x05150c, 0x051511, 0x051512, 0x051514,
0x051521, 0x051522, 0x051524, 0x051849, 0x05184a, 0x05184c,
0x051851, 0x051852, 0x051854, 0x051861, 0x051862, 0x051864,
0x051889, 0x05188a, 0x05188c, 0x051891, 0x051892, 0x051894,
0x0518a1, 0x0518a2, 0x0518a4, 0x051909, 0x05190a, 0x05190c,
0x051911, 0x051912, 0x051914, 0x051921, 0x051922, 0x051924,
0x052249, 0x05224a, 0x05224c, 0x052251, 0x052252, 0x052254,
0x052261, 0x052262, 0x052264, 0x052289, 0x05228a, 0x05228c,
0x052291, 0x052292, 0x052294, 0x0522a1, 0x0522a2, 0x0522a4,
0x052309, 0x05230a, 0x05230c, 0x052311, 0x052312, 0x052314,
0x052321, 0x052322, 0x052324, 0x052449, 0x05244a, 0x05244c,
0x052451, 0x052452, 0x052454, 0x052461, 0x052462, 0x052464,
0x052489, 0x05248a, 0x05248c, 0x052491, 0x052492, 0x052494,
0x0524a1, 0x0524a2, 0x0524a4, 0x052509, 0x05250a, 0x05250c,
0x052511, 0x052512, 0x052514, 0x052521, 0x052522, 0x052524,
0x052849, 0x05284a, 0x05284c, 0x052851, 0x052852, 0x052854,
0x052861, 0x052862, 0x052864, 0x052889, 0x05288a, 0x05288c,
0x052891, 0x052892, 0x052894, 0x0528a1, 0x0528a2, 0x0528a4,
0x052909, 0x05290a, 0x05290c, 0x052911, 0x052912, 0x052914,
0x052921, 0x052922, 0x052924, 0x054249, 0x05424a, 0x05424c,
0x054251, 0x054252, 0x054254, 0x054261, 0x054262, 0x054264,
0x054289, 0x05428a, 0x05428c, 0x054291, 0x054292, 0x054294,
0x0542a1, 0x0542a2, 0x0542a4, 0x054309, 0x05430a, 0x05430c,
0x054311, 0x054312, 0x054314, 0x054321, 0x054322, 0x054324,
0x054449, 0x05444a, 0x05444c, 0x054451, 0x054452, 0x054454,
0x054461, 0x054462, 0x054464, 0x054489, 0x05448a, 0x05448c,
0x054491, 0x054492, 0x054494, 0x0544a1, 0x0544a2, 0x0544a4,
0x054509, 0x05450a, 0x05450c, 0x054511, 0x054512, 0x054514,
0x054521, 0x054522, 0x054524, 0x054849, 0x05484a, 0x05484c,
0x054851, 0x054852, 0x054854, 0x054861, 0x054862, 0x054864,
0x054889, 0x05488a, 0x05488c, 0x054891, 0x054892, 0x054894,
0x0548a1, 0x0548a2, 0x0548a4, 0x054909, 0x05490a, 0x05490c,
0x054911, 0x054912, 0x054914, 0x054921, 0x054922, 0x054924,
0x061249, 0x06124a, 0x06124c, 0x061251, 0x061252, 0x061254,
0x061261, 0x061262, 0x061264, 0x061289, 0x06128a, 0x06128c,
0x061291, 0x061292, 0x061294, 0x0612a1, 0x0612a2, 0x0612a4,
0x061309, 0x06130a, 0x06130c, 0x061311, 0x061312, 0x061314,
0x061321, 0x061322, 0x061324, 0x061449, 0x06144a, 0x06144c,
0x061451, 0x061452, 0x061454, 0x061461, 0x061462, 0x061464,
0x061489, 0x06148a, 0x06148c, 0x061491, 0x061492, 0x061494,
0x0614a1, 0x0614a2, 0x0614a4, 0x061509, 0x06150a, 0x06150c,
0x061511, 0x061512, 0x061514, 0x061521, 0x061522, 0x061524,
0x061849, 0x06184a, 0x06184c, 0x061851, 0x061852, 0x061854,
0x061861, 0x061862, 0x061864, 0x061889, 0x06188a, 0x06188c,
0x061891, 0x061892, 0x061894, 0x0618a1, 0x0618a2, 0x0618a4,
0x061909, 0x06190a, 0x06190c, 0x061911, 0x061912, 0x061914,
0x061921, 0x061922, 0x061924, 0x062249, 0x06224a, 0x06224c,
0x062251, 0x062252, 0x062254, 0x062261, 0x062262, 0x062264,
0x062289, 0x06228a, 0x06228c, 0x062291, 0x062292, 0x062294,
0x0622a1, 0x0622a2, 0x0622a4, 0x062309, 0x06230a, 0x06230c,
0x062311, 0x062312, 0x062314, 0x062321, 0x062322, 0x062324,
0x062449, 0x06244a, 0x06244c, 0x062451, 0x062452, 0x062454,
0x062461, 0x062462, 0x062464, 0x062489, 0x06248a, 0x06248c,
0x062491, 0x062492, 0x062494, 0x0624a1, 0x0624a2, 0x0624a4,
0x062509, 0x06250a, 0x06250c, 0x062511, 0x062512, 0x062514,
0x062521, 0x062522, 0x062524, 0x062849, 0x06284a, 0x06284c,
0x062851, 0x062852, 0x062854, 0x062861, 0x062862, 0x062864,
0x062889, 0x06288a, 0x06288c, 0x062891, 0x062892, 0x062894,
0x0628a1, 0x0628a2, 0x0628a4, 0x062909, 0x06290a, 0x06290c,
0x062911, 0x062912, 0x062914, 0x062921, 0x062922, 0x062924,
0x064249, 0x06424a, 0x06424c, 0x064251, 0x064252, 0x064254,
0x064261, 0x064262, 0x064264, 0x064289, 0x06428a, 0x06428c,
0x064291, 0x064292, 0x064294, 0x0642a1, 0x0642a2, 0x0642a4,
0x064309, 0x06430a, 0x06430c, 0x064311, 0x064312, 0x064314,
0x064321, 0x064322, 0x064324, 0x064449, 0x06444a, 0x06444c,
0x064451, 0x064452, 0x064454, 0x064461, 0x064462, 0x064464,
0x064489, 0x06448a, 0x06448c, 0x064491, 0x064492, 0x064494,
0x0644a1, 0x0644a2, 0x0644a4, 0x064509, 0x06450a, 0x06450c,
0x064511, 0x064512, 0x064514, 0x064521, 0x064522, 0x064524,
0x064849, 0x06484a, 0x06484c, 0x064851, 0x064852, 0x064854,
0x064861, 0x064862, 0x064864, 0x064889, 0x06488a, 0x06488c,
0x064891, 0x064892, 0x064894, 0x0648a1, 0x0648a2, 0x0648a4,
0x064909, 0x06490a, 0x06490c, 0x064911, 0x064912, 0x064914,
0x064921, 0x064922, 0x064924, 0x089249, 0x08924a, 0x08924c,
0x089251, 0x089252, 0x089254, 0x089261, 0x089262, 0x089264,
0x089289, 0x08928a, 0x08928c, 0x089291, 0x089292, 0x089294,
0x0892a1, 0x0892a2, 0x0892a4, 0x089309, 0x08930a, 0x08930c,
0x089311, 0x089312, 0x089314, 0x089321, 0x089322, 0x089324,
0x089449, 0x08944a, 0x08944c, 0x089451, 0x089452, 0x089454,
0x089461, 0x089462, 0x089464, 0x089489, 0x08948a, 0x08948c,
0x089491, 0x089492, 0x089494, 0x0894a1, 0x0894a2, 0x0894a4,
0x089509, 0x08950a, 0x08950c, 0x089511, 0x089512, 0x089514,
0x089521, 0x089522, 0x089524, 0x089849, 0x08984a, 0x08984c,
0x089851, 0x089852, 0x089854, 0x089861, 0x089862, 0x089864,
0x089889, 0x08988a, 0x08988c,
...

Tue, 24 Aug 2004 03:25:10 GMT
Need help with Arrays: Specific program question
Quote:

> [snip - formatted]
> > > I have to write a program to determine all of the possible
> > > words that can be made from a 7 digit telephone number. The
> > > output would look like this:

> > > TAD-DWVR... and so on

(snip)
> I think you missed the point. Output all the possible "words" for a
> *given* 7-digit phone number...

(snip new version, with huge table).

Why the huge table? How about (somewhat shortened
for brevity and a few magic numbers embedded):

#include <stdio.h>
#include <string.h>

#define NUMLEN 7

int
while (--i >= 0) {
if (++alphapad[i] < 3) return 1;
}
return 0;

Quote:
}

int
main(int argc, char *argv[]) {
int i;

if (argc != 2 ||
strlen(argv[1]) != NUMLEN ||
strspn(argv[1], "23456789") != NUMLEN) {
fprintf(stderr, "usage: %s <phone number 7*[2-9]>\n", argv[0]);
return 1;
}
do {
for (i=0; i < NUMLEN; i++) {
if (i == 2) putchar('-');
}
putchar('\n');
return 0;

Quote:
}

/Svante

Tue, 24 Aug 2004 04:22:17 GMT
Need help with Arrays: Specific program question

[snip]

Quote:
> (snip new version, with huge table).

> Why the huge table? How about (somewhat shortened
> for brevity and a few magic numbers embedded):

I wanted to write a program with a table. They make small programs look
complicated and mysterious :-)

[snip]

Quote:
> int
>     int i = sizeof (alphapadT);
>     while (--i >= 0) {
>         if (++alphapad[i] < 3) return 1;
>     }
>     return 0;
> }

This works too, although this particular implementation did not occur to
me last night at 3 in the morning. Instead, I spent a lot of time
generating and formatting tables :-)

david

--
If 91 were prime, it would be a counterexample to your conjecture.
-- Bruce Wheeler

Tue, 24 Aug 2004 05:35:41 GMT
Need help with Arrays: Specific program question
(snip)

Quote:
> I wanted to write a program with a table. They make small programs look
> complicated and mysterious :-)

Fair enough! You certainly succeeded - I never did figure out
the table, so I gave up and did it my way instead ;-)

(snip)

Quote:

> This works too, although this particular implementation did not occur to
> me last night at 3 in the morning. Instead, I spent a lot of time
> generating and formatting tables :-)

It happens - timezones can shift the creative advantage at times.
I'm GMT+1 so I got my thinking done at prime time!

/Svante

Tue, 24 Aug 2004 06:07:22 GMT

 Page 1 of 2 [ 17 post ] Go to page: [1] [2]

Relevant Pages