C Program to Implement Character Count in Data Link Layer

C Program to implement character count in data link layer. A data connection is a method of linking two locations for the purpose of transmitting and receiving digital data. A link protocol governs them, allowing digital data to be transported from a data source to a data sink. 

Data Link Layer

A data connection is a method of linking two locations for the purpose of transmitting and receiving digital data (data communication). It may also refer to a group of electronics assemblies that include a transmitter and a receiver (two pieces of data terminal equipment) as well as the data telecommunication circuit that connects them. A link protocol governs them, allowing digital data to be transported from a data source to a data sink. This is main concept to execute c program to implement character count in data link layer.

Count Keyword in C

Counting is a sequence of whole numbers in ascending order that does not include zero. Creating a counting program in the C programming language is simple, as we will see in this chapter. Counting is used to determine the amount of numbers or items in a list. Counting may be used to keep track of how many iterations your program has gone through in a loop.

Gets in C

The C gets function reads or scans a line of text from a standard input (stdin) device and stores it in the String variable. The C gets function will be terminated when it reads the newline character. 

Increment Operator in C

Increment Operators are unary operators that are used to increase or add one to the operand value. The double plus sign (++) represents the Increment operand. It is divided into two types: pre-increment and post-increment operators.

If Else Statement in C

If a particular condition is true, the if/else statement executes a block of code. If the condition is not met, another piece of code can be run. The if/else statement is a type of “Conditional” Statement in JavaScript, which is used to conduct different actions based on distinct situations. c program to implement character count in data link layer for beginners to understand program.

#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k,l,count=0,n; char s[100],cs[50];
printf("\n Enter the bit string");
gets(s);
n=strlen(s);
printf("\nString is\n");
for(i=0;i<n;i++)
{
if(s[i]==s[i+1])
{
count=2; i++;
while(s[i]==s[i+1])
{ i++;
count++;
}
if(count>=5)
{
printf("$");
if(count<10)
printf("0");
printf("%d%c",count,s[i]);
i++;
}
else
{
for(j=0;j<count;j++)
printf("%c",s[i]);
i++;
}
}
else
{
printf("%c",s[i]);
i++;
}
}
}

Output:

Enter the bit string123NSCNSDLKCNSDLCNKSC

String is
13SNDKNDCKC