GCC Write a program that modifies a word by replacing every alphabetical letter
ID: 3711699 • Letter: G
Question
GCC
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:
Input: TAKEOUT
Output: 8253688
Your program should include the following function: void convert(char *word, char *numbers);
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.
1) Name your program word_numbers.c.
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.
I do not want this answer, this has a compiling error and it uses convert(char, int) instead of convert(char, char)
#include <stdio.h>
#include <math.h>
#include<string.h>
void convert(char * word,int n)
{
int u;
while(n)
{
if(*word=='S'||*word=='V'||*word=='Y'||*word=='Z')
{
if(*word=='S')
printf("7");
if(*word=='V')
printf("8");
if(*word=='Y'||*word=='Z')
printf("9");
word++;
n--;
continue;
}
u= (*word-65)/3;
printf("%d",u+2);
word++;
n--;
}
}
int main()
{
char a[1000];
int n;
printf("Enter the text to be converted ");
scanf("%s",a);
n=strlen(a);
convert(a,n);
}
Explanation / Answer
The program ran good without any errors when I ran it on turbo c++.
It gave an error of infinite loop when i ran it on an online IDE.
It ran but without satisfactory output on another IDE.
So, for the correct answer of this question, post the errors, or ask for the full solution to the problem.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.