Home / C (page 5)


C program for Lamport Logical Clock

Lamport Logical Clock C program

Lamport Logical Clock to find the ordering of events in a Distributed System. In Lamport Algorithm each event has its own timestamp which depends on the occuring of events in the order the message has been sent by which event of a process to whichever event. #include<stdio.h> #include<conio.h> int max1(int a, int b) //to find the maximum timestamp between two ...

Read More »

Program to find a substring in a given string

This program is to find a substring 1101 in a given string. This is also used for string matching . #include<stdio.h> #include<conio.h> void main() { char s[20]; char p[]="1101"; int i, count=0; clrscr(); printf("enter Your String = "); scanf("%s",s); for(i=0;s[i]!='\0';i++) { if(s[i]==p[count] ) count++; else count=0; if ( count == 4) { printf("\n Substring %s found in the given string", ...

Read More »

Character array c / character array java

Character array in c and character array in java can be implemented in two ways:   1. Character array using pointers:  Using pointer you can assign a string value to a character array however it will still work as an character array not as a string. The pointer will point to the first index of your assigned string. char *arr=”hello”;      or char ...

Read More »

How to Null a string or empty a string array

Null a String/ Empty a string array Null a string in C using pointer string or array string. Many times the string is nullified assigning arr[0]=’\0′ but this will not nullify the array as only the first index will be NULL.   1. Null a string using pointer string. char *ptr="hello"; printf("%s" , ptr); *ptr='\0'; printf("\n %s  and  %s ",ptr,ptr+1); ...

Read More »

C Program to count prime numbers in given range

This is the program to count total number of Prime numbers with in 1 to specified range  #include<conio.h> long countprime(long a,long k) { long i; for(i=a;i>=2;i--) { if(k%i==0) return 0; } return 1; } void main() { long i,range; long count=1; double x; printf("Enter the range: "); scanf("%ld\n",&range); for(i=3;i<range;i++) { x=sqrt(i); count+=countprime(floor(x),i); } printf("\n Total number of prime numbers are ...

Read More »

C Program for Bit Stuffing

Bit stuffing in network lab C C++ programming

Bit Stuffing: In bit stuffing following rules hold:-  To the given bits add the string 01111110 to both the starting and the end of the string To add 0 to each set of 5 one’s i.e. after every five consecutive 1’s appear a zero #include "stdio.h" #include "conio.h" int main() { int i=0,count=0; char a[100]; printf("enter the bits : "); scanf("%s",a); printf("\nAfter ...

Read More »

C Program to implement CRC (Cyclic Redundancy Code)

Cyclic Redundancy Code

This is a C Program for implementing CRC (Cyclic Redundancy Check Code) #include <stdio.h> #include <conio.h> #include <string.h> void main() { int i,j,keylen,msglen; char input[100], key[30],temp[30],quot[100],rem[30],key1[30]; clrscr(); printf("Enter Data: "); gets(input); printf("Enter Key: "); gets(key); keylen=strlen(key); msglen=strlen(input); strcpy(key1,key); for(i=0;i<keylen-1;i++) { input[msglen+i]='0'; } for(i=0;i<keylen;i++) temp[i]=input[i]; for(i=0;i<msglen;i++) { quot[i]=temp[0]; if(quot[i]=='0') for(j=0;j<keylen;j++) key[j]='0'; else for(j=0;j<keylen;j++) key[j]=key1[j]; for(j=keylen-1;j>0;j--) { if(temp[j]==key[j]) rem[j-1]='0'; else rem[j-1]='1'; } ...

Read More »

C Program for Add two Numbers Using Pointers without Operators

C Program for Add two Numbers Using Pointers without Operators | C program to  sum up two nos This is the simple c program which takes two numbers as input and give addition of those number as output. this program doesn’t use any operator for that purpose.  Program 1: C program to add two numbers using pointers | Without using operators  ...

Read More »

C Program for Implementation of Regular Expession

C Program for implementing DFA of Regular Expression (a+aa*b)* In this program you have to enter a string and output will be shown as  whether string will be accepted or not. Program is implemented using transition table not jumping on different states. It can be easily modifiable for other regular expressions.  #include<stdio.h> #include<conio.h> #include<strings.h> void main() { int table[2][2],i,j,l,status=0,success; char ...

Read More »