Skip to main content

Posts

Program to remove left factoring of grammar

Program to remove left factoring of grammar :  #include<iostream.h> #include<stdio.h> #include<conio.h> #include<string.h> //Structure Declaration struct production {             char lf;             char rt[10];             int prod_rear;             int fl; }; struct production prodn[20],prodn_new[20];      //Creation of object //Variables Declaration int b=-1,d,f,q,n,m=0,c=0; char terminal[20],nonterm[20],alpha[10],extra[10]; char epsilon='^'; //Beginning of Main Program void main() {    clrscr();    //Input of Special characters    cout<<"\nEnter the number of Special characters(except non-terminals): ";    cin...

Declare variable as constant in C

Variables can be declared as constant using the const keyword or the #define preprocessor directive. Details about these are given as follows. The const keyword Variables can be declared as constants by using the “const” keyword before the datatype of the variable. The constant variables can be initialized once only. The default value of constant variables are zero. A program that demonstrates the declaration of constant variables in C using const keyword is given as follows. Example Live Demo #include <stdio.h> int main () { const int a ; const int b = 12 ; printf ( "The default value of variable a : %d" , a ); printf ( "\nThe value of variable b : %d" , b ); return 0 ; } The output of the above program is as follows. The default value of variable a : 0 The value of variable b : 12 The #define preprocessor directive Variables can be declared as constants by using the #define preprocessor directive as it dec...

Send and Receive JSON over sockets in server and client application in C

I want to send the data in JSON over sockets in a server-client application written in C. I am using json-c / libjson library for handling JSON data in C application. By working on some of the tutorials I am able to create JSON object and able to parse it successfully. Now I want to use the JSON data format for the communication of server-client. Here is part of my server and client code server.c int main () { int listenfd = 0 , connfd = 0 ; //related with the server struct sockaddr_in serv_addr ; //json_object * jobj; uint8_t buf [ 158 ], i ; memset (& buf , '0' , sizeof ( buf )); listenfd = socket ( AF_INET , SOCK_STREAM , 0 ); serv_addr . sin_family = AF_INET ; serv_addr . sin_addr . s_addr = htonl ( INADDR_ANY ); serv_addr . sin_port = htons ( 8888 ); bind ( listenfd , ( struct sockaddr *)& serv_addr , sizeof ( serv_addr )); printf ( "binding\n" ); listen ( listenf...