C and C++ Compiler Design

POSIX compliant program to check the following limits: (i) No. of clock ticks (ii) Max. no. of child processes (iii) Max. path length (iv) Max. no. of characters in a file name (v) Max. no. of open files/ process

#define _POSIX_SOURCE #define _POSIX_C_SOURCE 199309L #include<stdio.h> #include<unistd.h> int main() { int res; if((res = sysconf(_SC_OPEN_MAX)) == -1) perror(“sysconf”); else printf(“OPEN_MAX:%d\n”,res); if((res = pathconf(“/”, _PC_NAME_MAX)) == -1) perror(“pathconf”); else printf(“max_path name:%d\n”,res); if((res = sysconf(_SC_CLK_TCK))== -1) perror(“sysconf”); else printf(“clock ticks:%d\n”,res); if((res = sysconf (_SC_CHILD_MAX)) == -1) perror(“sysconf”); else printf(“max_childs:%d\n”,(res)); if((res = pathconf(“/”,_PC_PATH_MAX)) == -1) perror(“pathconf”); else printf(“max […]

C and C++ OS Shell Script

Program to count the number of characters words spaces and lines in a given input file

%{ #include int c=0,s=0,w=0, l=0; %} %% [ ] {s++;} [\n] {l++;} [^\t\n]+ {w++; c=c+yyleng;} %% main(int argc, char *argv[ ]) { FILE *fp; if(argc == 2) { fp = fopen(argv[1],”r”); if(!fp) { printf(“file doesnot exist\n”); exit(0); } yyin = fp; yylex(); printf(“number of spaces is %d\n”,s); printf(“number of character is %d\n”, c); printf(“number of […]

C and C++

C program that recreates a child process to read commands from the standard input and execute them

#include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<unistd.h> #include<wait.h> #define BUFF 20 int main() { char buff[BUFF]; int Pid = 0, i, ret, returnval; Pid = fork(); if(Pid == 0) { for(;;) { for(i=0; i<BUFF; i++) buff[i] = ‘\0’; write(STDOUT_FILENO, “SHELL>”, 6); read(STDIN_FILENO, buff, BUFF); if(strcmp(buff,”exit\n”) == 0) exit(100); ret = system(buff); printf(“exit status of the command = %d\n”, […]

C and C++ Data Structures

Find shortest paths to other vertices using Dijkra’s algorithm

What is Dijkstra’s Algorithm? Dijkstra’s Algorithm is a popular graph traversal technique used to find the shortest path between nodes in a weighted graph. Developed by Edsger W. Dijkstra in 1956, this algorithm is a cornerstone in fields like computer networks, GPS navigation, artificial intelligence, and routing protocols. Key Features of Dijkstra’s Algorithm Works on […]

Implement any scheme to find the optimal solution for the travelling salesman problem C and C++ Data Structures

Implement any scheme to find the optimal solution for the travelling salesman problem

Travelling Salesman Problem Using Nearest Neighbour Algorithm in C The Nearest Neighbour (NN) algorithm is a greedy heuristic method for solving the Travelling Salesman Problem (TSP). Though it doesn’t guarantee the optimal solution, it provides a quick and fairly efficient approximation, especially useful for large datasets where brute-force or dynamic programming becomes infeasible. /* Nearest […]

C and C++

Characteristics of C Programming languages

Direct access to memory layout through pointer manipulation Concise syntax, small set of keywords Block structured language Some encapsulation of code, via functions Type checking (pretty weak) C is portable(program written for one computer can be run on another computer with little modification) C has an ability to extend itself. C was invented to write […]

Explain Flowcharts C and C++ Data Structures

Explain Flowcharts

It is a diagram showing a sequence of activities to be performed for the solution of a problem. • A set of conventional symbols are used to draw flowcharts • Graphically depicts the logical steps to carry out a task and shows how the steps relate to each other. • An organized combination of shapes, […]

C and C++

Program to converting degree to radian using type conversion

In C++ programming, understanding type conversion is essential for precise mathematical computations. One common real-world application is converting angles from degrees to radians. This is especially useful in trigonometry, graphics, physics simulations, and embedded systems. In this tutorial, we’ll write a C++ program to convert degrees to radians using type conversion to ensure accuracy in […]

Program to convert decimal to binary using templates

Templates in C++ allow you to write generic and reusable code. By using function templates, you can create flexible functions that work with various data types. In this tutorial, you’ll learn how to write a C++ program to convert a decimal number to binary using a function template, enhancing both your understanding of binary number […]