Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Write C Program Prompts User Enter Series Integers Represent Coded Message Given Decoder P Q35581929

Write a C program that prompts the user to enter a series ofintegers that represent a coded
message. I have given you the decoder program so that you can seehow it is written using
array notation. Your assignment is to convert the code to a programthat uses only pointers
and pointer math.
Your program must use pointer notation and pointer math (i.e. noarray index notation
other than in the declaration section, no arrays of pointers and nopointer 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.

Also note that what the user types in is indicated by the boldedblack text above. Again, for
clarity only. (The text will limited to an 80 character message. Totest, copy and paste the
entire line of digits above).

The below sample provides a solution to the program using”array” notation, remember we need to use pointer notation. Youshould use it as a guide and just modify the code to usepointer
notation.

Note: An arrow line comment (< —-) can be found on the codethat needs to be removed and replaced by pointer notation.

// HINT: decoder program using arrays

#include <stdio.h>

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(“nEnter all the string digits to decode:n”);
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() != ‘n’);
  
// 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] = ”; //<————***

printf(“nn”);
printf(“n decoded: n”);
  
i = 0;
while(t[i] != ”) //<————***
{
printf(“%c”, t[i]); //<————***
i++; //<————***
}// end while
  
printf(“nn”);
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 . . .

Leave a Reply

Your email address will not be published. Required fields are marked *