Hi all,
So I'm trying to do this checksum problem for my C programming class but im running into some difficulty. My output is supposed to be this:
Line: This is short.
Checksum: 2
Line: The quick brown fox jumped over the lazy dog.
Checksum: =
Line: A.
Checksum: O
Line: B.
Checksum: P
Line: C.
Checksum: Q
Line: .
But I'm getting this:
Line: This is short.
Checksum:
Line: The quick brown fox jumped over the lazy dog.
Checksum: !
Line: A.
Checksum: /
Line: B.
Checksum: 0
Line: C.
Checksum: 1
Line: .
Checksum: .
This is my code
#include <stdio.h>
int main ()
{
while(1)
{
char str[50] = {0};
int num = 0;
char final_val;
printf("Line: "); // Request Line
scanf("%s", str); // Read in Line
int i;
for (i = 0; i<=49; i++)
{
num+=str[i];
}
num = num%64;
final_val = num;
num = 0;
printf("\nChecksum: %c", final_val);
printf("\n");
return(0);
}
The program is supposed to accept single-line messages ending with a period and displays the checksum character for each message. It should continue displaying checksums until the user enters a line with only a period. I am really stumped on this... can anyone help me out?