Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Name your program word_numbers.c. Your program should include the following f

ID: 3700259 • Letter: 1

Question

1) Name your program word_numbers.c. Your program should include the following function: void convert(char *word, char *numbers);

2) Assume input is no longer than 1000 characters.

3) The convert function should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the function. 4) To read a line of text, use the read_line function (the pointer version) in the lecture notes.

Write a program that modifies a word by replacing every alphabetical letter (lower case or upper case) with a digit (2-9). The numbers 2 through 9 each have three letters associated with them, as is indicated by the following table:

Digit Letter

2 A B C

3 D E F

4 G H I

5 J K L

6 M N O

7 P Q R S

8 T U V

9 W X Y Z

The function expects word to point to a string containing to be translated; numbers represents the pointer pointing to the string storing the numbers. For example, if the word is TAKEOUT, the function will store 8253688 pointed by numbers.

Explanation / Answer

#define _CRT_SECURE_NO_DEPRECATE

#include<stdio.h>

void convert(char *word, char *numbers);

int main()

{

int i;

char str[] = "TAKEOUT",numbers[10];

convert(str, numbers);

printf("Word %s to number: %s ", str,numbers);

}

void convert(char *word, char *numbers)

{

int i;

char c;

for (i = 0; i < strlen(word); i++)

{

//convert a letter to lower case

c = tolower(word[i]);

switch (c)

{

case 'a':

case 'b':

case 'c':

*(numbers + i) = 48 + 2;

break;

case 'd':

case 'e':

case 'f':

*(numbers + i) = 48 + 3;

break;

case 'g':

case 'h':

case 'i':

*(numbers + i) = 48 + 4;

break;

case 'j':

case 'k':

case 'l':

*(numbers + i) = 48 + 5;

break;

case 'm':

case 'n':

case 'o':

*(numbers + i) = 48 + 6;

break;

case 'p':

case 'q':

case 'r':

case 's':

* (numbers + i) = 48 + 7;

break;

case 't':

case 'u':

case 'v':

*(numbers + i) = 48 + 8;

break;

case 'w':

case 'x':

case 'y':

case 'z':

* (numbers + i) = 48 + 9;

break;

}

}

numbers[i] = '';

}

/*output

Word TAKEOUT to number: 8253688

*/