This post contains C program to simulate grep command in Linux or Unix operating systems
Simulation of grep command in Linux
#include<stdio.h>
#include<string.h>
main()
{
Information about resetting and configuring Mobile phones (Java, Android, Symbian etc), educational articles especially for programming in C, C++ and Java and more about Computers and operating systems
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
C Program to Simulate grep Command in Linux
Labels:
$ccpp
,
c program
,
code
,
command
,
compiled
,
GREP
,
lab
,
Linux
,
operating Systems
,
OS lab
,
programming
,
simulate
,
simulation
,
source code
,
terminal
,
UNIX
Using System calls in C Program to rename a Directory in Linux
C Program to rename a directory in Unix or Linux operating systems using system call rename().
#include<stdio.h>
main()
{
#include<stdio.h>
main()
{
Labels:
$ccpp
,
c program
,
code
,
compiled
,
directory
,
How to
,
lab
,
Linux
,
operating Systems
,
OS
,
OS lab
,
programming
,
rename
,
source code
,
system call
,
UNIX
How to Create process and display Process ID (pid) of Both Parent and Child
This program shows how to create process and display Process ID (pid) of Both Parent and Child processes. The process is created using the fork system call in UNIX (Linux) operating systems.
#include<stdio.h>
#include<dirent.h>
main(int argc,char **argv)
{
#include<stdio.h>
#include<dirent.h>
main(int argc,char **argv)
{
Labels:
$ccpp
,
c program
,
code
,
compiled
,
create
,
display
,
fork
,
getpid
,
lab
,
Linux
,
operating Systems
,
OS
,
Oslab
,
process
,
process id
,
programming
,
source code
,
system call
,
UNIX
How to use exit() System call
C program to show how to use exit system call. The function exit() is used to exit from a process (or to terminate a process). This works both in Linux or UNIX and Windows operating systems.
#include<stdio.h>
main()
{
#include<stdio.h>
main()
{
Labels:
$ccpp
,
c program
,
code
,
compiled
,
exit
,
lab
,
Linux
,
operating Systems
,
OS
,
programming
,
source code
,
system call
,
UNIX
,
Windows
How to make parent process wait till Completion of Child Process (Joining parent with child process)
How to make the parent process wait till the completion of execution of child process. The following C program makes the parent process to wait till the completion of its child process.
#include<stdio.h>
main()
{
#include<stdio.h>
main()
{
How to make Child process an Orphan Process
C program in Linux or Unix to make a child process orphan:
Making child as orphan
#include<stdio.h>
main()
{
Making child as orphan
#include<stdio.h>
main()
{
C Program To Implement Circular Linked List
C Program to implement circular linked list.
#include<stdio.h> #include<malloc.h> #include<stdlib.h>
Labels:
$ccpp
,
c program
,
C++
,
circular
,
code
,
compiled
,
delete
,
ends
,
insert
,
linked
,
linked list
,
list
,
programming
,
source code
,
two
C Program To Represent Directed or Undirected Graph Using Adjacency Matrix
C program to represent directed or undirected graph using Adjacency matrix.
#include<stdio.h> #include<conio.h> #define max 20 int adj[max][max]; //Adjacency matrix int n; //Denotes number of nodes in the graph void main() {
Labels:
$ccpp
,
adjacency
,
c program
,
code
,
create
,
data structure
,
directed
,
graph
,
graphs
,
How to
,
matrices
,
matrix
,
programming
,
represent
,
representation
,
undirected
,
using
Storage Classes for Variables in C Programming Language
Every variable in C programming language has two properties; type and storage class. 'Type' refers to the data type of the variable such as integer, character, floating point values etc. It also deals with the size of the variable ( in bytes). 'Storage class' determines the part of memory where storage is allocated for the variable and how long the storage allocation continues to exist. It also determines the scope which specifies the part of the program over which a variable name is visible, i.e. the variable is accessible by name. The scope restriction can be overrode by making use of pointers. Whatever, in short, storage class is the property that determines the part of memory where storage is allocated, the lifetime of variable and the scope of the variable.
There are for storage classes in C programming:
There are for storage classes in C programming:
- Automatic
- Register
- External
- Static
Intel 8085 Microprocessor Instructions - Hex codes and Mnemonics
In this post, we will see the 8085 Microprocessor instructions and corresponding hex codes. This table is useful to hand assemble the 8085 program. In many universities, 8085 programming is included for practicals under computer science and engineering courses. Each mnemonic has its own hex codes. An assembler is a program which converts the code written in mnemonics into hexadecimal codes. The monitor program (part of microprocessor kit) translates the hex codes to corresponding actions to be performed by CPU.
Get 8085 Simulator (with assembler) for computer
Get 8085 Simulator for Mobile
Labels:
$studymat
,
assembler
,
assembly
,
code
,
hex code
,
hexadecimal
,
instructions
,
Intel 8085
,
language
,
level
,
microprocessor
,
mnemonics
,
programming
C and C++ Programs to Reverse a Number
This post includes a C program and a C++ program to reverse a given number. That is, to reverse the order of digits. If 543 is entered, it will be displayed as 345.
C Program:
#include<stdio.h> main() {
Labels:
$ccpp
,
c
,
c plus plus
,
c program
,
C++
,
code
,
compiled
,
given
,
How to
,
number
,
order
,
palindrome
,
practical
,
programming
,
reverse
,
source code
Conditional Operator in C and C++
Conditional Operator is an operator which is substitutive for if-else statements. It is a ternary operator (operator which operates on 3 operands). It is often called ?: operator. The operands are expression1, expression2 and expression3. The syntax is as follows:
The expression expression1 will be evaluated always. Execution of expression2 and expression3 depends on the outcome of expression1. expression1 is checked whether true or not. It is considered like a boolean variable. The outcome of an expression is true if it has a non zero value. If its value is zero, the outcome of expression is false. If the expression1 is true, then expression2 is evaluated. If the expression1 is false, then expression3 is evaluated. Consider the following example:
expression1 ? expression2 : expression3
The expression expression1 will be evaluated always. Execution of expression2 and expression3 depends on the outcome of expression1. expression1 is checked whether true or not. It is considered like a boolean variable. The outcome of an expression is true if it has a non zero value. If its value is zero, the outcome of expression is false. If the expression1 is true, then expression2 is evaluated. If the expression1 is false, then expression3 is evaluated. Consider the following example:
Linear Search in C and C++ Languages
Linear search simply means 'looking for an element in the whole array from one end to the other'. The searched element is compared with the first element of array first, then with the second, then with the third, so on upto the end of the array. This is time consuming when the array is pretty enough. The time complexity is highest.The C and C++ programs for linear search is given below.
C Program:
C Program:
#include<stdio.h> void main() {
C and C++ Programs to Check Whether a Number is Strong Number or Not
This post contains C and C++ program to check whether a given number is Strong number or not. A strong number is a number for which the sum of factorials of its digits is equal to the number itself. The first one is C program to check whether the input number is a strong number or not. An example is 145. 1!+4!+5!=1+24+120=145 Therefore 145 is a strong number.
C Program:
C Program:
#include<stdio.h> long int factorial(int n) {
Labels:
$ccpp
,
c
,
C++
,
check
,
code
,
compiled program
,
is checking
,
language
,
not
,
number
,
or
,
program
,
programming
,
source code
,
strong
,
whether
String Comparison in C and C++ Languages and Working of strcmp function
In both C and C++ programming languages, an inbuilt function strcmp() is used to compare two strings. This function is defined in string.h header file. So, to use this function, you have to include the header file string.h in the program. Most of the people ( i mean beginners) have a wrong idea about the working of the this function. I also had made some false assumptions. This function takes two strings as arguments. And it compares the two strings using the ASCII equivalent of each character. Some of the false ideas about this function are:
- The function returns 1 when the strings are equal and 0 when they are not equal
- The function returns 1 when they are not equal
- The function returns 1 when the first string is greater than the second and returns -1 when the first one is less than the second one
Labels:
$ccpp
,
c program
,
C++
,
codes
,
comparison
,
function
,
inbuilt
,
language
,
programming
,
return value
,
strcpy
,
string
,
string compare
,
string sort
C Program for Subtraction Without Using Minus Sign
The following is a program to subtract a number from another without using minus symbol. Instead of doing a normal subtract operation, the two's complement of the subtrahend is added to the minuend. (In 3-4, 3 is minuend and 4 is subtrahend.) In other words, the 1's complement and 1 is added to minuend.
#include<stdio.h> void main() { int a,b,sum; printf("Enter any two integers: ");
scanf("%d%d",&a,&b); sum = a + ~b + 1; printf("Difference of two integers: %d",sum); }
Labels:
$ccpp
,
1's
,
2's
,
c
,
complement
,
language
,
one's
,
program
,
programming
,
source code
,
subtraction
,
two's
C and C++ Programs to Find Sum of Digits of a Given Number
The following are C and C++ programs to find sum of digits of any given integer.
C Program
C Program
#include<stdio.h> #include<conio.h> void main() {
2 Different C and C++ Programs to Check Whether a Given String is Palindrome or Not
Here i am writing two different programs to check whether a given string (text) us palindrome or not. There are C and C++ programs for this.
C Programs:
(i) Using string functions:
(ii) Comparing Character by Character
C++ Programs:
(i) Using String functions:
C Programs:
(i) Using string functions:
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char a[100],b[100]; printf("Enter the string to check if palindrome or not\n"); gets(a); strcpy(b,a); strrev(b); if(strcmp(a,b)==0) printf("\nEntered string is palindrome"); else printf("\nEntered string is not palindrome"); getch(); }
(ii) Comparing Character by Character
#include<string.h> #include<stdio.h> #include<conio.h> void main() { int len,i; char a[100]; printf("Enter the string to check whether it is palindrome or not\n"); gets(a); len=strlen(a); for(i=0;i<len/2;i++) { if(a[i]!=a[len-i-1]) break; } if(i==len/2) printf("\nEntered string is palindrome"); else printf("\nEntered string is not palindrome"); getch(); }
C++ Programs:
(i) Using String functions:
Labels:
$ccpp
,
c language
,
c plus plus
,
C programming
,
C++
,
code
,
coding
,
cpp
,
programming
,
programming language
,
programs
,
project
,
source code
C and C++ Programs to Check Whether a Given Number is Armstrong Number or Not
This post contains two programs, a C++ program and a C program. These are programs to check whether a given number is an Armstrong number or not. An Armstrong number is a positive integer for which the sum of 'n'th power of all of its digits is equal to the number itself. For example, 153 is a 3 digit Armstrong number because 13+53+33=153.
C ++ program:
C Program:
C ++ program:
# include <iostream.h> # include <conio.h> # include <math.h> void main () { clrscr(); int a,b=0,sum=0; long int n; cout<<"Enter the number to be checked\n "; cin>>n; if(n<1) { cout<<"\nThe number should be greater than 0"; } else { a=n; //counting the digits while (a>0) { a=a/10; b++; } a=n; //adding up bth power of digits while(a>0) { sum=sum+pow(( a%10) ,b); a=a/10; } if(sum==n) cout<<"\nThe number is an ARMSTRONG number"; else cout<<"\nThe number is NOT an ARMSTRONG number"; } getch(); }
C Program:
# include <stdio.h> # include <conio.h> # include <math.h> void main () { clrscr(); int a,b=0,sum=0; long int n; printf("Enter the number to check\n "); scanf("%i",&n); if(n<1) { printf ("\nThe number should be greater than 0"); } else { a=n; //counting the digits while (a>0) { a=a/10; b++; } a=n; //adding up bth power of digits while(a>0) { sum=sum+pow(( a%10) ,b); a=a/10; } if(sum==n) printf ("\nThe number is an ARMSTRONG number"); else printf ("\nThe number is NOT an ARMSTRONG number"); } getch(); }
Labels:
$ccpp
,
Armstrong
,
Armstrong numbers
,
c
,
C++
,
check
,
code
,
computer program
,
given number
,
number
,
or not
,
program
,
programme
,
programming
,
programming language
,
source code
,
whether
C Program to Check Whether a Given String is Palindrome or Not
Here i am writing two different programs two check whether an input string is palindrome or not. The first program checks the string manually character by chatter from both ends. The other program make use of a string function strrev() (under string.h) to reverse the string. Therefore, the second program is more compact.
Program 1:
Program 1:
#include<stdio.h> #include<string.h> void main() { char a[20]; int i, len; printf("\nEnter the string:\n"); gets(a); len = strlen(a); for (i = 0; i < len / 2; i++) { if (a[i] != a[len - i - 1]) break; }
Labels:
$ccpp
,
c
,
c language
,
check
,
code
,
computer
,
or not
,
palindrome
,
program
,
programming
,
sentence
,
source code
,
string
,
whether
,
word
Subscribe to:
Posts
(
Atom
)