Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder

Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder program so that you can see how it is written using array notation. Your assignment is to convert the code to a program that uses only pointers and pointer math.

Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section, no arrays of pointers and no pointer offsets).

The dialog with the user might look like:

Enter string digits to decode:

109 138 145 145 148 81 69 142 153 76 152 69 146 138 70 10

Enter the secret offset integer: 37

Decoded:

Hello, it's me!

Note: The bold text represents the "user input" from your program and is shown for clarity only here. It is not required that your output be in this color. (Do not even attempt to try!). Also note that what the user types in is indicated by the bolded black text above. Again, for clarity only. (The text will limited to an 80 character message. To test, copy and paste the entire line of digits above).

Below is a sample which provides a solution to the program using "array" notation. You should use it as a guide and just modify the code to use pointer notation.
Note: An arrow line comment (< ----) can be found on the code that needs to be removed and replaced by pointer notation.
SAMPLE
HINT: decoder program using arrays
#include
void safer_gets(char [], int);
int main()
{
int i, x, y;
char c;
int v[81]={0}; // stores the coded string in number form
char t[81]; // stores the string that was coded
// user enters a string to be decoded:
printf(" Enter all the string digits to decode: ");
i=0;
do
{
scanf("%i", &v[i]); //<------------***
if(v[i] == 10) break; //<------------***
i++; //<------------***
}while(i < 81); // end while //<------------***
// now enter an offset number:
printf("Enter the secret offset integer: ");
scanf("%i", &x);
while(c = getchar() != ' ');
// now decode and convert to string
i = 0;
while(v[i] != 10) //<------------***
{
y = v[i]; //<------------***
t[i] = y - x; //<------------***
i++; //<------------***
}// end while loop
t[i] = '\0'; //<------------***
printf(" ");
printf(" decoded: ");
i = 0;
while(t[i] != '\0') //<------------***
{
printf("%c", t[i]); //<------------***
i++; //<------------***
}// end while
printf(" ");
return 0;
}// end main
/*
sample runs:
Enter string digits to decode:
109 138 145 145 148 81 69 142 153 76 152 69 146 138 70 10
Enter the secret offset integer: 37
decoded:
Hello, it's me!
Press any key to continue . . .
Enter string digits to decode:
84 113 133 44 115 123 123 112 44 120 123 123 119 117 122 51 56 44 131 116 109 128 111 116 109 44 115 123 128 44 111 123 123 119 117 122 51 75 10
Enter the secret offset integer: 12
decoded:
Hey good lookin', whatcha got cookin'?
Press any key to continue . . .
*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions