Question

Since communications channels are often noisy, numerous ways have been devised to ensure reliable data transmission....

Since communications channels are often noisy, numerous ways have been devised to ensure reliable data transmission. One successful method uses a checksum. A checksum for a message can be computed by summing the integer codes of the characters in the message and finding the remainder of this sum divided by 64. The integer code for a space character is added to this result to obtain the checksum. Since this value is within the range of the displayable characters, it is displayed as a character as well. Write a program that accepts single-line messages ending with a period and displays the checksum character for each message. Your program should continue displaying checksums until the user enters a line with only a period.

Provided template and program constraints:

Constraints : calc_sum() must have return type of void
             : calc_sum() must have one "output parameter", ie, pass by reference
             : main() must print the results.
Example     : Enter a message:matlab.
Output      : checksum = Q
============================================================================
*/
#include

int main(){
        int sum=0;
        calc_checksum(&sum);
        /* Enter some code here to print result*/
        return 0;
}

Example:

Enter a message:matlab.
checksum = Q                  ^-------- note the period (.) at the end to mark the end.

Note: Do not use an array to solve this problem.

This has to be coded in the C programming language and done by modifying the template code provided.

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

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void calc_checksum(int *n)
{
char c;

//now convertint to checksum
int sum=0;
int i=0;
printf("Enter message:");
while(true)
{
//printf("i:%d\n",i);
c=getchar();
if(i==1 && c =='.')
{printf("--exiting--");
exit(0);}
else if(c=='.')
break;
sum=sum+c;//adding integer codes
i++;
}sum=sum%64;//finding reminder
sum+=' ';//space is added
*n=sum;
}
int main(){
int sum=0;
while(1)
{sum=0;
calc_checksum(&sum);
/* Enter some code here to print result*/
//printing result
printf("output:%c\n",(char)sum);
}return 0;
}

output:

Enter message:matlab.
output:Q
Enter message:hello.
output:>
Enter message:surya.
output:^
Enter message:.
--exiting--

Process exited normally.
Press any key to continue . . .


Add a comment
Know the answer?
Add Answer to:
Since communications channels are often noisy, numerous ways have been devised to ensure reliable data transmission....
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
  • Write the code in C language. Computer communication networks sometimes have noise on them, which can...

    Write the code in C language. Computer communication networks sometimes have noise on them, which can corrupt data being transmitted. It is the responsibility of the computers communicating to confirm data is transmitted accurately. One method to do this is to calculate a checksum of the data and transmit the checksum along with the data to ensure accuracy. In C, we can compute a checksum simply by summing the integer ASCII codes in the message and finding the remainder of...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • I need help implementing the following code without using filehandling and only getchar(); this is the...

    I need help implementing the following code without using filehandling and only getchar(); this is the prompt "The input for your program will be a text file containing a large amount of English. Typically, an English sentence ends with a period (aka, dot). Many years ago, when people used mechanical typewriters, the proper form was to place one space between words in a sentence, but two spaces after the period at the end of the sentence. This rule is no...

  • In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

    In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...

  • Java Switch Case Make From Pseudocode

    The following pseudo-code describes a menu-driven algorithm:loopask the user to input one of the characters a, b, c, d, e, q read in a character from the keyboardif the character is'a' output your name and your tutor's name (hard-coded) 'b' input 3 double numbers x, y, z and output the largestand the smallest of the three numbers'c' input 2 integer numbers m and n, and display all thenumbers between m and n (both inclusive) with five numbers per line (note...

  • JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information...

    JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...

  • This project is designed to practice with OOP, stack data structure, its applications, and C++/Java programming...

    This project is designed to practice with OOP, stack data structure, its applications, and C++/Java programming language. You will write a program that reads an infix expression, converts it to a postfix expression, evaluates the postfix expression, and prints out the answer. You must define and implement your own Stack class and a Calculator class. Your Stack class supports standard basic stack operations and you can implement it with an array or a linked list. You should create a class...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

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