I decided to take #rstanley's advice and purchased the book he recommended. C Programming a modern approach which doesn't give the answers to all the questions. So I'm forced to struggle which I don't mind but, I've hit a wall and if there is a google search that will give me the answer, I can't find it.

This program is a work in progress. In short:
If I use:
Code:
number=3;     // it works
number=arr[j];    // it doesn't work. even though arr[] contains int values. Probably the answer is obvious to you but, I'm completely beaten on this.
This is commented in the code below.

Code:
// trying to complete chap 10 #7 on page 239 of Book: C Programming, A Modern Approach 2nd Edition by K.N. KING
// above builds on chapt 8 ex 6 on page 177


#include <stdbool.h>        // required to declare with bool
#define MAX_DIGITS 10


int arr[MAX_DIGITS];
int k=0;
const int segments[10][7]={
        {1,1,1,1,1,1,0},    // 0
        {0,1,1,0,0,0,0},    // 1
        {1,1,0,1,1,0,1},    // 2
        {1,1,1,1,0,1,0},    // 3
        {0,1,1,0,0,1,1},    // 4
        {1,0,1,1,0,1,1},    // 5
        {1,0,1,1,1,1,1},    // 6
        {1,1,1,0,0,0,0},    // 7
        {1,1,1,1,1,1,1},    // 8
        {1,1,1,1,0,1,1}};   // 9
int digits[4][MAX_DIGITS];  // Directions aren't clear. p240 says multiply MAX_DIGITS * 4.  Not using yet anyway.


void clear_digits_array(void);                  // store blank characters into all elements of the digits array
void process_digit(int digit, int position);    // stores the 7 segment representation of digit into a specified position in the digits array
void print_digits_array(void);                  // displays the rows of the digits array, each on a single line


int main(){
    int ch[1];
    clear_digits_array();


    printf("Enter a 7 digit phone number (E.g. 123-4567): ");
        while(k<MAX_DIGITS){
            scanf("%c", &ch[0]);
            if(ch[0]=='0' || ch[0]=='1' || ch[0]=='2' || ch[0]=='3' || ch[0]=='4' || ch[0]=='5' || ch[0]=='6' || ch[0]=='7' || ch[0]=='8' || ch[0]=='9'){
                process_digit(ch[0], k);   // pass the int and the counter to function
            }else if(ch[0]=='\n'){
                break;
            }
            ++k;
        }
    print_digits_array();
}


void clear_digits_array(void){
    for(int j=0;j<MAX_DIGITS;j++){
        arr[j]='\0';
    }
}


void process_digit(int digit, int position){
    arr[position]=digit;
    printf("arr[%d] = %c\n", position, arr[position]);
}


void print_digits_array(void){
    int number, numLess, num;
    for(int i=0;i<3;i++){
        for (int j=0;j<k+1;j++){
            number=arr[j];                                  // HERE IS THE PROBLEM: change arr[j] to 3 and it works. it seems that the variable 'number' is NOT AN INT!
            //num = atoi(number);                           // doesn't work
            numLess=number-1;
            printf("segments[%c][0] = %d\n",numLess, segments[numLess][0]); // BUG IS HERE: numLess prints as int but, isn't int.
            if(i==0){
                if(segments[number][0]==1){printf("  _");}
            }
            if(i==1){
                if(segments[number][5]==1){printf(" |");}
                if(segments[number][6]==1){printf("_");}
                if(segments[number][1]==1){printf("|");}
            }


            if(i==2){
                if(segments[number][4]==1){printf(" |");}
                if(segments[number][3]==1){printf("_");}
                if(segments[number][2]==1){printf("|");}
            }
        }
    }
}
With
Code:
number=3;
It works (see in red):
Enter a 7 digit phone number (E.g. 123-4567): 678
arr[0] = 6
arr[1] = 7
arr[2] = 8
segments[☻][0] = 1
_segments[☻][0] = 1
_segments[☻][0] = 1
//rest not shown...

With
Code:
number=arr[j];
It doesn't work (see in red):
Enter a 7 digit phone number (E.g. 123-4567): 678
arr[0] = 6
arr[1] = 7
arr[2] = 8
segments[5][0] = 0
segments[6][0] = 0
segments[7][0] = 0
//rest not shown...

I declared arr[] as an int. I assume that it only contains int values but, when I grab a value out of the array, it seems to assume that it is a char or something. What am I not understanding.

I know there are lots of bugs especially in the function print_digits_array() but, this is a WIP and I need to figure out the other bugs on my own. I'm sure it's hard to look at this code and not wince.

Any insight is appreciated.

Sincerely,

Michael