0% found this document useful (0 votes)
25 views3 pages

Framing Techniques in Data Transmission

The document contains a C program that implements three framing methods: Character Count, Character Stuffing, and Bit Stuffing. Users can input a maximum of 5 data frames and choose a framing method to display the formatted output. The example provided demonstrates the Character Stuffing method with sample data.

Uploaded by

enjoybaap6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Framing Techniques in Data Transmission

The document contains a C program that implements three framing methods: Character Count, Character Stuffing, and Bit Stuffing. Users can input a maximum of 5 data frames and choose a framing method to display the formatted output. The example provided demonstrates the Character Stuffing method with sample data.

Uploaded by

enjoybaap6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <stdio.

h>
#include <string.h>

void characterCountFraming(char data[5][100], int n) {


printf("\n--- Character Count Framing ---\n");
for (int i = 0; i < n; i++) {
int len = strlen(data[i]);
printf("Frame %d: [%d]%s\n", i + 1, len, data[i]);
}
}

void characterStuffing(char data[5][100], int n) {


printf("\n--- Character Stuffing ---\n");
char start = 'S', end = 'E', esc = '\\';

for (int i = 0; i < n; i++) {


printf("Frame %d: ", i + 1);
printf("%c", start);
for (int j = 0; j < strlen(data[i]); j++) {
if (data[i][j] == start || data[i][j] == end || data[i][j] == esc) {
printf("%c", esc); // Escape character
}
printf("%c", data[i][j]);
}
printf("%c\n", end);
}
}

void bitStuffing(char data[5][100], int n) {


printf("\n--- Bit Stuffing ---\n");
char flag[] = "01111110";

for (int i = 0; i < n; i++) {


printf("Frame %d: %s", i + 1, flag);
int count = 0;
for (int j = 0; j < strlen(data[i]); j++) {
if (data[i][j] == '1') {
count++;
printf("1");
if (count == 5) {
printf("0"); // Stuffed 0
count = 0;
}
} else {
printf("0");
count = 0;
}
}
printf("%s\n", flag);
}
}

int main() {
int choice, n;
char data[5][100];

printf("Enter number of frames (max 5): ");


scanf("%d", &n);
getchar(); // to consume newline

for (int i = 0; i < n; i++) {


printf("Enter data for frame %d: ", i + 1);
fgets(data[i], sizeof(data[i]), stdin);
data[i][strcspn(data[i], "\n")] = '\0'; // remove newline
}

printf("\nChoose Framing Method:\n");


printf("1. Character Count\n2. Character Stuffing\n3. Bit Stuffing (binary only)\n");
printf("Enter choice: ");
scanf("%d", &choice);

switch (choice) {
case 1: characterCountFraming(data, n); break;
case 2: characterStuffing(data, n); break;
case 3: bitStuffing(data, n); break;
default: printf("Invalid choice\n");
}

return 0;
}
Enter number of frames (max 5): 3
Enter data for frame 1: cccc
Enter data for frame 2: ddd
Enter data for frame 3: ttt

Choose Framing Method:


1. Character Count
2. Character Stuffing
3. Bit Stuffing (binary only)
Enter choice: 2

--- Character Stuffing ---


Frame 1: SccccE
Frame 2: SdddE
Frame 3: StttE

You might also like