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

Character Stuffing

The document provides a C program that implements character stuffing to handle special frame delimiters. It defines functions to read an input string, process it by adding delimiters around specific characters, and then outputs both the original and stuffed strings. The program uses Turbo C and includes necessary header files for string manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

Character Stuffing

The document provides a C program that implements character stuffing to handle special frame delimiters. It defines functions to read an input string, process it by adding delimiters around specific characters, and then outputs both the original and stuffed strings. The program uses Turbo C and includes necessary header files for string manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Aim: Write a program in C, to perform character stuffing.

Software Required: Turbo C Program:

#include <stdio.h>

#include <string.h>

#define FRAME_START_DELIMITER '~'

#define FRAME_END_DELIMITER '~'

// Function to perform character stuffing

void characterStuffing(char* input, char* stuffed) {

int stuffed_index = 0;

int i = 0;

for (i = 0; i < strlen(input); i++) {

if (input[i] == FRAME_START_DELIMITER || input[i] == FRAME_END_DELIMITER) {

// Add frame delimiters before and after the stuffed character

stuffed[stuffed_index++] = FRAME_START_DELIMITER;

stuffed[stuffed_index++] = input[i];

stuffed[stuffed_index++] = FRAME_END_DELIMITER;

} else {

// Just copy the character as it is

stuffed[stuffed_index++] = input[i];
}

// Null terminate the stuffed string

stuffed[stuffed_index] = '\0';

int main() {

char input[100], stuffed[200];

// Get the input string safely

printf("Enter the input string: ");

fgets(input, sizeof(input), stdin);

// Remove the newline character that fgets may add

input[strcspn(input, "\n")] = '\0';

// Perform character stuffing

characterStuffing(input, stuffed);

// Print the results

printf("Original string: %s\n", input);

printf("Stuffed string: %s\n", stuffed);

return 0;
}

You might also like