Saturday, December 29, 2012

Using OpenCV in GTK sample program "Inverting an image on Image Processing"

In this article I want to show you How we can use the OpenCV on GTK (GIMP toolkit) on fedora.Although GTK+ is a GNU project like the GMP, it is released under the terms of the more liberal LGPL(lesser general public license) that permits software (including closed source proprietary software) to be written using GTK+ without payment of fees, royalties, or other restirictions. The freedom offered by the GTK+ license is in contrast to its competitor QT(you must instead purchase a commercial Qt license in that case).
This program is compile using gcc compiler on fedora. At first you need to install the gtk and gnome on your machine.
In fedra that use RPM packages, you should have at least install the following RPM package.
$  su

$  yum install gtk2
$  yum install gtk2-devel
$  yum install gtk2-engines
$  yum install libgnome-
$  yum install libgnome-devel
$  yum install libgnomeui
$  yum install libgnomeui-devel

Now its time to install OpenCV package.

Using semaphore to synchronize the multiple thread using c on linux/fedora

Semaphore is a new type of variable introduced by E. W. Dijkstra. You may learn about semaphores in university. It is used to solve the Producer-Consumer Problem in Operation system design which I have learn in books "Modern Operating Systems " (second edition) by Andrew S. Tanenbaum. In that books the algorithm for semaphore is clearly defined and easy to understand. But I was always curious about that "Does this type of problem occur on our program?" rather than operating system design and "Where can I use it?". When I begin to learn linux programming I found the semaphore function under <semaphore.h> header and example program where semaphore is used to synchronize the thread.
In this article we look at the simplest type of semaphore, a binary semaphore that takes only values 0 or 1. There is also a more general semaphore that takes a wider range of values. Normally, semaphores are used to protect a piece of code so that only one thread of execution can run it at any one time.The semaphore functions do not start with pthread_,as most thread-specific functions do,but with sem_. Four basic semaphore functions are used in threads. They are all quite simple.

Friday, December 28, 2012

Threads Program using c on linux/fedora


This program creates a single extra thread, shows that it is sharing variables with the original thread, and gets the new thread to return a result to the original thread. Multithreaded programs don't get much simpler than this.
Lets look the function which create the thread. pthread_create creates a new thread,much as fork creates a new process.
#include<pthread.h>
int pthread_create(pthread_t *thread, pthread_attr_t *attr, void(*start_routine)(void *), void *arg);
The first argument is a pointer to pthread_t . When a thread is created, an identifier is written to the memory location to which this variable points.This identifier enables you to refer to the thread . The next argument sets the thread attributes. You do not usually need any special attributes, and you can simply pass NULL as this argument. Later is the chapter you will see how to use these attributes. The final two arguments tell the thread the function that it is to start executing and the arguments that are to be passed to this function.

Tuesday, December 25, 2012

Bash Shell Scripting example project "library management"



This program is a sample shell script. To understand this project you must know the basic syntax of shell programming. In this article I tried to show an example how we can use a shell as a programming language. I have build the very simple shell script for managing a library books. If you are completely new to shell programming in Linux then at search the following topic on Google about their syntax and uses before proceeding this article. List of topic are:
  1. variables
  2. if condition
  3. switch case
  4. printf ,read , echo command
  5. while loop, for loop
  6. grep command
  7. function declaration
Now if you have learn above topic in shell programming then you can understand this project library management. In this project simple features are included like adding books, editing books information,remove and search books and view all books. Lets start the project.

Saturday, December 1, 2012

Creating Static Libraries using c on linux Fedora.

You have seen the library file  ".lib" extension on Windows and a ".a" on LINUX/UNIX.If you are unknown about what are they and how to create them then you will get answer here.
These are Static Library files, also known as archives, which are simply a collection of ordinary object files. It is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable. Simply we can say it permit users to link to programs without having to recompile its code, saving recompilation time.
There are several advantages of static libraries:
1.The most significant is that the application can be certain that all its
    libraries are present and that they are the correct version. This avoids
    dependency problems.
2. Result in a significant performance improvement.
3. Can be shared between many applications leading to space savings.
4. It also allows the library to be updated to fix bugs and security flaws
    without updating the applications that use the library.

Friday, November 16, 2012

Start learning C on Linux (Fedora)

We students learn c on windows . We create the executable file (.exe) using turbo c or gcc compiler that runs only in windows machine. Have you tried the c on Linux and generating executable file for Linux? Not yet then follow this article.
In this article you learn how to:
1. Install  linux (e.g fedora or ubuntu)
2. Install  gcc compiler in fedora
3. Compile the c program using gcc.
You will also understand what are the executable file in Linux.

Saturday, August 4, 2012

C project on Medical Store Management System with source

This is large and complete c project built for medical store management system. In this project you can keep details of customer , suppliers and medicine. You can view the report and billing information also. You can add,edit, delete and search the record also. This project is also console application without graphics compile in code::blocks IDE with MinGW compiler.
Whole project is completely based on file handling all the record are store in file. You learn how to store the data ,editing data, searching data and deleting data using file. You can see the following feature in this projects.
1. Supplier Info
2.Customer Info
3.Medicine
4.Report
5.Bill

Employee’s Management System Project in c++ with source

This is another Mangagement project which is suitable for school or college mini project. It is written in c++ language in code::blocks IDE with MinGW compiler. It is console application without graphics. Whole project is completely based on file handling all the employee’s record are store in file. You learn how to store the data, editing data, searching data and deleting the data using file. Following features can be found in this project which is listed below.
1. Built The Employee table
2.List the employee table
3.Insert new entry
4.Delete an entry
5.Edit an entry
6.Search a record
7.Sort the table

Thursday, July 19, 2012

Project on Visual C++::Server to Exchange Data between text file and Excel

In this program we use Dynamic Data Exchange (DDE)  with Notepad and Excel. Using Visual C++ a DDE communication server is made to exchange date. If we change the any data in Notepad then automatically data is updated in Excel. By same way we can also use Dynamic Data Exchange with Word and Excel. When possible, it is recommended that you use Automation, not DDE, to communicate with Excel or Word. DDE is a old method or technology. Excel and Word have rich object models that provide functionality through Automation that is not available with DDE. Excel versions 5.o and later , and Word versions 7.0 and later, support Automation. But who are using old version of Excel where Automation is not supported then DDE can be a better solution. I can't explain the program and DDE better than MSDN site so I will provide the reference link where you can learn it . 

Wednesday, June 27, 2012

C++ Project Bus Reservation System in Code::blocks

“Bus Reservation System” project is written in c++. It is very simple project just to show the implement of class and object of C++. You can understand the code easily and learn how to create class and use object in c++ for your C++ project.The tasks that user can perform in this project are listed below:
1.Install the bus record
2.Reservation
3.Show the bus details
4.Show all buses available
This project is console application without GUI. You can add many features in this project.Here data of bus information is not store in file so every run of program previous data is lost so you can implement the file handling to store all the bus details.

Code::blocks Project Bank Management System in C programming

Bank Management System project is design and programmed by Ravi Agrawal, Sagar Sharma and Sawal Maskey student of IOE as a first year mini project in c. This program may not be used as a Banking software but programmer tries to implement all the features of Bank. Program is completely password protected and has a two mode Admin and Staff mode. Bank administrator can login as admin user name is “admin” and password is “ioe” for admin mode. For staff mode three  user name is available which is written in USER.DAT which you can see download this project. The list of user name and passwor for staff mode is given below: 

School Project Personal Diary Management in C programming

This project is similar to the project Contact Management in C. In this project, I am reusing all the code from it. I created this Personal Diary Management project just by renaming printed messages, adding a few functions, and modifying existing functions slightly.

Please go through the Contact Management project if you haven't. In this project, I have explained the techniques of file handling in C.

So, in this project, I will explain the changes that I have made.

Let's start with describing data structure.
// Define Constant Variables
#define ESC 27
#define REF_SZ 10
#define DATE_SZ 64
#define MIN_TEXT_SZ 50
#define MAX_TEST_SZ 500
#define READ_ARRAY_SZ 15
#define DATA_FILE "dataFile.dat"
#define TEMP_FILE "tempFile.dat"

//Define data structure

struct data{
    char refNum[REF_SZ]; //Unique reference number and auto-incremented
    char noteDate[DATE_SZ]; //Auto populated using system date and time
    char eventDate[DATE_SZ]; //Event date
    char location[MIN_TEXT_SZ]; //Location of event happened
    char eventDesc[MIN_TEXT_SZ]; //Event short description
    char notes[MAX_TEST_SZ]; //Notes of the Event
};
I am using 6 variables in a structure. The variable "refNum" will be unique and it is auto-increment. The variable "noteDate" is to store note added date and it is also auto-populated using system date and time. 

Other variables are:
  • eventDate: Event date. It can be any format chosen by the user
  • location: Location of event happened.
  • eventDesc: Event short description.
  • notes: Notes of the event. Maximum character is 500.
Although the variable refNum is auto-incremented, I haven't defined it as an integer. Rather than storing number value only, I decided to add '#R' as an initial character so that the unique reference value will look like "#R10001" instead of "1000".

To achieve this we have to create two separate small functions which I will describe below.

Function: getNextRef()
//Get next reference number

int getNextRef(){

    struct data a;
    int num=0;
    fp = fopen(DATA_FILE,"rb");

    if(fp!= NULL){

        fseek(fp,0,SEEK_END);

        fseek(fp,ftell(fp)-sizeof(a),0);
        fread(&a,sizeof(a),1,fp);

        // converting string to number
        for (int i = 0; a.refNum[i + 2] != '\0'; i++) {
            num = num * 10 + (a.refNum[i + 2] - 48);
        }
        fclose(fp);
        return num;

    } else {

        return 10000;
    }
}
This function will read the last item from the file and read the reference number which is the previous reference number and also the highest value. It will remove the first two characters, convert the remaining numbers into an integer data type, and return it. This function will be executed at the start of the application so if it does not find a file then it will return 1000. 

Function: calRefNum(char *buff, int num)
//Calculate next reference number
static void calRefNum(char *buff, int num){

    char tmpRef[REF_SZ];
    char refNum[REF_SZ] = {'#','R'};
    sprintf(tmpRef,"%d",num);
    strcat(refNum, tmpRef);
    strcpy(buff,refNum);
}
This function converts the reference number into char data type, concatenates with the "#R" initial character, and assigns it to a character pointer which is used while adding notes.

Apart from these changes I have made a few changes in readData(), add(), and view() functions. Once you compile and run it you will understand the changes.

Please download the source code from the GitHub Download Source Code.

You can also watch a video about this project on YouTube.


Telecom Billing Management System in c with source code

This Mini project is compile in gcc compiler with code::blocks IDE. This project can be a good reference for those student who are doing there school project in c.Architecture of this project is very simple and easy to understand the code. Just file handling is used to store the data and corresponding function are made to manipulate the data.
The tasks provide in this program are:-
1. A : for adding new records.
2. L : for list of records.
3. M : for modifying records.
4. P : for payment.
5. S : for searching records.
6. D : for deleting records.
User are provide the above tasks.They can add records,modify and view records. Searching and deleting facilities is also provided.

Download Project from GitHub


Tuesday, May 29, 2012

Simple method for texture mapping on sphere Using gluSphere and gluQuadricTexture in OpenGL

In my previous article [here] I have shown you how to map texture in solid sphere. In that method whole sphere is render using triangles and providing texture co-ordinates which seems difficult to understand. Now in this article I am going to show you simple method to map texture on Sphere. We first draw a sphere using gluSphere and texture co-ordinates are automatically generated by gluQuadricTexture function for Sphere.
gluSphere:
syntax:
void WINAPI gluSphere( GLUquadric *qobj, GLdouble radius, GLint slices, GLint stacks);

Wednesday, May 9, 2012

Creating multiple windows with OpenGL and GLUT

We may need the multiple OpenGL windows for our program for example we can show orthographic view of object (top view, side view,front view)  in separate  windows.
Steps for Creating Multiple Windows:-
1.Initialize drawing context and frame buffer using glutInit(), glutInitDisplayMode(), and glutInitWindowSize().
2.Create first window
3.Register callbacks for first window
4.Create second window
5.Position the second window
6.Register callbacks for second window
7.Register (shared) idle callback
8.Enter the main loop
Note: Callbacks can be shared between windows, if desired



Saturday, April 28, 2012

GLFW Tutorial 4: Texture mapping sample code in OpenGL Framework

If you are new to the GLFW(OpenGL framework) you can follow beginning tutorial here.
On Contrary with GLUT texture mapping is very easy in GLFW . We want to use pre-generated 2D images for surface textures, light maps, transparency maps etc.These images are stored with a standard image format in a file, which requires the program to decode and load the      image(s) from file(s), which can require much work from the programmer.To make programming easier for OpenGL developers, GLFW has built-in support for loading images from files.
In this tutorial I give example for surface textures only. Surface textures are important because it helps to make object realistic.
To load a texture from a file, you can use the function glfwLoadTexture2D:
int glfwLoadTexture2D( const char *name, int flags )
This function reads a 2D image from a Truevision Targa format file (.TGA) with the name given by name, and uploads it to texture memory. It is similar to the OpenGL function glTexImage2D, except that the image data is read from a file instead of from main memory, and all the pixel format and data storage flags are handled automatically. The flags argument can be used to control how the texture is loaded. If flags is GLFW_ORIGIN_UL_BIT, the origin of the texture will be the upper left corner (otherwise it is the lower left corner). If flags is GLFW_BUILD_MIPMAPS_BIT, all mipmap levels will be generated and uploaded to texture memory (otherwise only one mipmap level is loaded). If flags is GLFW_ALPHA_MAP_BIT, then any gray scale images will be loaded as alpha maps rather than luminance maps. To make combinations of the flags, or them together (e.g. like this: GLFW_ORIGIN_UL_BIT |GLFW_BUILD_MIPMAPS_BIT).
Here is the sample program to illustrate the texture mapping with complete source code written in c++ with gcc compile and code::blocks IDE. You can also download the project file.

Tuesday, April 17, 2012

GLFW(OpenGL FrameWork) tutorial 3:Transformation:Translation,Scaling and Rotation.

If you are beginner to OpenGL FrameWork (GLFW) visit my previous tutorial lesson Here so that you can understand in details.Translation ,Scaling and Rotation of object is so easy because OpenGL provide these command to us we don’t have to write our own  Transformation matrix.

Translation command:

Translation is movement along any of the three axis in a 3D scene, for example, moving something the left is a translation on the X axis if you are looking straight on.
Command:
glTranslatef( xValue, yValue, zValue );
e.g:
glTranslate(5.0, 0.0, 0.0);
This translate the scene five unit along positive x-axis. One things you must remember ,all the scene drawn below this command will be translated.
So,if you want to translate only one object then you have to restore the transformation. Restore can be done by putting drawing scene and translation command between glPushMatrix() and glPopMatrix() .

Monday, April 16, 2012

GLFW (OpenGL Framework) tutorial 2: Drawing Basic Shapes

Lets first discuss how OpenGL does. Describing co-ordinates system of OpenGL, center of co-ordinate is middle of widow, positive x-axis is pointed towards right and negative x-axis toward left ,positive y-axis is pointed towards up and negative y-axis towards bottom , positive z-axis is pointed towards outside of screen and negative z-axis towards inside the screen.
  • coord_system
OpenGL draw object similar to our eye . By default eye is in origin and we are looking toward negative z-axis.

GLFW tutorial 1:Introduction to OpenGL Framework

Welcome to codeincodeblock.blogspot.com I have created this tutorial for 3D programming in OpenGL for beginners. OpenGL has wide range of use some of them is Gamming ,simulation, virtual prototyping. This tutorial provide only basic knowledge of OpenGL in brief with full source code and complete explanation so, that you can move quickly to advanced OpenGL programming. All tutorials is written in c++ so that you must know the basic c++ to understand this tutorial.
We use OpenGL for 3d programming. You may wondering what is OpenGL. OpenGL is software interface for graphics hardware in other word we can say it is language translator so that we can use only one language for different graphics hardware. OpenGL is hardware independent. We can draw both 3D and 2D stuff. For 2D their are better libraries like SDL ,Allegro. We use OpenGL basically for 3D stuff.
I use GLFW library and code::blocks IDE. You may confused reading OpenGL and using GLFW library, what does GLFW means? The creation of a window to render stuff in is not covered in the OpenGL specification. This is handled by platform-specific APIs. GLFW is one of this  APIs. It is a crossplatform windowing and keyboard/mouse/joystick handler. Contrary to GLUT, this is more aimed for creating games. Supports Windows, Mac OS X and Unix-like systems such as Linux and FreeBSD.
You don’t have code::blocks IDE then download it form Here .There are two options of download so, choose codeblocks-10.05mingw-setup.exe file in which MinGW compiler is already install. Then you need to setup the GLFW library in code::blocks. Follow my previous article Setup GLFW Project for setup.
Now you are ready for OpenGL 3d programming..
Goto tutorial 2 Drawing Basic Shape

Friday, April 13, 2012

List of Top Ten College Mini Projects in c/c++ with full source code

If you need to make a Mini project in c/c++ language and you are confused about the project topic then don’t worry here is the list of the Top 10 Mini Projects in c/c++ you can choose any one of them. The source code of all projects is also available. All the projects are compiled in gcc compiler with code::blocks IDE so some projects may create errors in different compilers like Turbo c/c++. If you are using Turbo c then choose another compiler it is an old compiler. The best one is the gcc/g++ compiler for c and C++.
All projects are collected by my college friends and me. Some of the projects are also edited to run in gcc compiler with code::blocks IDE from other websites. For your query and suggestion send me mail at smokindinesh@gmail.com.
 Projects in C++ 
  1. Student database system
  2. Hang Man
  3. School Fee Enquiry Management System
  4. Supermarket Billing System
  5. 3D Bounce in OpenGL
  6. Bus Reservation System
  7. Puzzel Game in wxWidget
  8. Data Exchange between Notepad and Excel (Visual C++)
  9. Employee's Management System

Projects in c
  1. Quiz Game 

  2. Contacts Management   

  3. Personal Dairy Management System   

  4. Library management
  5. Snake Game
  6. Department store system
  7. Tic-tac-toe game
  8. Telecom Billing Management System
  9. Bank Management System
  10. Medical Store Management System

Please find the YouTube 

Sunday, February 12, 2012

Delay function in codeblocks

In code block you can use
Sleep(unsigned int miliseconds);
function for delay in execution.
delay(unsigned int miliseconds) function is used in turbo c. For codeblocks you have to add code which is given below example:
#include<stdio.h>
#include<time.h>
void delay(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock());
}
int main()
{
    int i;
    for(i=0;i<10;i++)
    {
    delay(1000);
    printf("This is delay function\n");
    }
    return 0;
}

Friday, February 3, 2012

Draw a 3D Rubik cube using OpenGL utility toolkits GLUT with source code

This article is similar  to my previous article drawing 3D chess board.To make Rubik cube real I have used texture mapping.At first I draw a one cube where I mapped texture in all six side of cube with six different color images and you can save these images from here.After that 27 cube is drawn by looping and final Rubik cube is drawn, rotating in (2,2,0) axis.For texture mapping we have to write a code to load a images and store a value of (R1,G1,B1,R2,G2,B2,……………)pixels in pixels array.In this project there is a Image class where you can see in source code below in file name imageloader.h and imageloader.cpp which I have take from a website www.videotutorialsrock.com.
All the images for this program is given below save it in your project file location.

Saturday, January 28, 2012

Mini project student database system in c++ source code download

This is simple student information system project.Wher you can do following things 1. Add    Records
          2. List   Records
          3. Modify Records
          4. Delete Records
          5. Exit   Program
to store data file is used. Download project from GitHub.

How to display a system date and time using c++

#include <ctime>
#include <iostream>
using namespace std;
 
int main() {
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );
    cout <<  now->tm_mday << '-'//day
         << (now->tm_mon +1 )  << '-'//month
         << (now->tm_year +1900 )//year
         <<endl
         <<now->tm_hour//hour
         <<'-'<<now->tm_min//min
         <<'-'<< now->tm_sec//sec
         << endl;
 
         return 0;
}

Wednesday, January 25, 2012

Mini project Hang Man in C++ source code download

It is a simple project just to provide a Hang Man game concept.In this project I haven’t draw a man for a wrong choice so,try to draw a simple man by using “|” pattern in your project which make your project better .
Here is the source code ,copy and compile it in Code::blocks gcc compiler or Download project from GitHub.

Mini project school fee enquiry management system in c++ source code download

This mini project is written by my friend in C++ which is simple console application without graphics.This is a fee structure program It can be used for following ways:-
1.We can  view the fee slip of a student of a class
2.We can also Modify the fee structure of the school
3.And View the fee structure of the school in the form of alist
The menu functions are described as follows
1. FEE SLIP:  This function displays the fee slip for a givenstudent
from the class entered by the user.
2. MODIFY:    This function modifies the fee structure for a give class.
The user can change the fees for various fields
3. LIST:      This function displays the list of total fees for all the
Here is the source code ,copy and compile it in gcc compiler with code::blocks IDE or Download project from GitHub.

Mini project supermarket billing system in c++ source code download

This mini project is written in C++ where you find mainly two classes one class item another class amount and class amount is inheritance form class item.It is simple console application without graphics. From this project you learn file handling in c++ and use of stream class.And main defect of this program is that goto label  is used to jump form one menu to another menu and separate function for editing  and deleting items are not used.So,if you want to make it your school project or college mini project then modify it ,make separate function for editing and deleting and also try to use while loop instead of goto label .Any suggestion and help for this project is appreciated .
Here is the source code ,copy and compile it in gcc with code::blocks IDE or Download project from GitHub.

Saturday, January 14, 2012

Star pattern program in c source code

1.Print a pattern
         *
      *  *
   *  *  *
*  *  *  *
To print this pattern we have to use three for loop.Inside the first loop there 
will be two loop, one is for controlling the spacing factor and another for 
printing the stars.Constant value of First loop is used in second inner loop to
decided the number of stars.
Here is the source code copy and paste it on code::blocks and run the program you
will see the result.