-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.c
More file actions
37 lines (32 loc) · 1.3 KB
/
Main.c
File metadata and controls
37 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* This C program calculates and verifies checksums for input data.
* It reads user input, calculates the checksum for the input data, and then verifies the checksum for received data.
* If the checksum matches, it indicates no errors; otherwise, it detects a checksum error.
**/
#include <stdio.h>
#include <string.h>
#include "Checksums.h"
#define MAX_SIZE 1000
int main() {
char data[MAX_SIZE];
unsigned short checksum;
printf("\n*******************************************************************************");
printf("---> Enter the data to calculate checksum: ");
fgets(data, MAX_SIZE, stdin);
// Removing newline character from input
data[strcspn(data, "\n")] = 0;
int dataSize = strlen(data);
checksum = calculateChecksum(data, dataSize);
printf("---> Checksum calculated: 0x%04X\n", checksum);
// Verification
printf("---> Enter the received data to verify: ");
fgets(data, MAX_SIZE, stdin);
data[strcspn(data, "\n")] = 0;
if (verifyChecksum(data, dataSize)) {
printf("*** No error in received data. Checksum verified. ***\n");
} else {
printf(" ( ! Error in received data. Checksum does not match. ! )\n");
}
return 0;
printf("*******************************************************************************\n");
}