Question

Write a C program that prompts the user to enter a series of integers that represent...

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 blue 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).

Really BIG hint:

You can click on the "decode_arrays.c" link 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: you have not provide the code but I have written the completely working code.

Code :

#include<stdio.h>
#include<conio.h>

//decoding is just subtracting offset from given number
char decode(int number,int offset)
{
   return number-offset;//returning decoded value
}

int main(int argc, char *argv[])
{
   //declaring variable
   //also declaring array here
   int i=0,size,arr[10000],offset,temp2;
char temp;
  
   //prompting for input
   printf("Enter string digits to decode:");
//take input until enter is pressed
   do{
scanf("%d%c", (arr+i), &temp); //(arr+i) is same as &arr[i], temp to store space or enter
i++; //increase i to get count
} while(temp!= '\n');//if temp is new line then break
   //prompting for offset
   printf("Enter the secret offset integer:");
   scanf("%d",&offset);

   //printing results
   printf("Decoded:\n");
   for(temp=0;temp<i;temp++){
       temp2=*(arr+temp); //only pointer is used to get array value
       printf("%c",decode(temp2,offset)); //calling decode to get char...remember char and int is same
   }

   getch();//just to hold screen. remove this and conio if you dont need this
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a C program that prompts the user to enter a series of integers that represent...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • JAVA Write a program that prompts the user to enter a file name, then opens the...

    JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...

  • With your partner, brainstorm a program that will ask the user for a number of digits...

    With your partner, brainstorm a program that will ask the user for a number of digits to be stored. The program should then create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Create a new Project named FillArray and a new class in the default packaged named FillArray.java. You and your partner should...

  • Please help C++ language Instructions Write a program that prompts the user to enter 50 integers...

    Please help C++ language Instructions Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs.

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • Write a program that asks the user to enter 1000 integers to be stored in an...

    Write a program that asks the user to enter 1000 integers to be stored in an array called "numbers". Since the same integer might occur (exist) in the array multiple times, your program needs to fill a second array, called "Isolate" that contains all the integers from the first array but NOT REPAPTED (every integer will exist only once). Finally, your program will print the integers of the second array sorted by occurrence (occurrence is: the number of times the...

  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT