Monday, 18 August 2014

today i am writing tutorial  that how to configure code-blocks to develop GUI using  gtk libraries.

(i was given a project called "budget monitoring system"  in the last summer holidays by my college and they said that i have to do this project using c language and project should completely GUI based, so i have searched on Google and found a way to develop GUI based applications using c language )


(1)  link to gtk:-
http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip
this link is a zip file of gtk. extract it in c drive

(2) link to glade:-
goto below link and log in and download   Glade Interface Designer Gtk+ 2 copy it in c drive.

link:->   https://my.pcloud.com/publink/show?code=kZJCiZm2wGcstvuyBN9m4mmdWmbmWwHzay

(3) code blocks:-
link:-> http://www.codeblocks.org/downloads/26  go to this link and
download   codeblocks-13.12mingw-setup.exe and install it.

(note:- if you already have code blocks with mingw installed then skip this)


now setup:-
step 1:- open codeblocks goto settings then click on compiler...
step2:-copy  `pkg-config --libs gtk+-2.0` and paste it in linker settings then in other linker options.
    example:


copy  `pkg-config --cflags gtk+-2.0` and  paste it in compiler settings then in other options
click ok and close the window.
 example:
 


step 3: now you have to setup environment variables
(note: according to windows 8)

right click on computer icon and  select properties.
now click on advanced system settings then click on environment variables.
 now find PATH in system variables then click on it and then click edit.
now add path's of bin directories of gtk and mingw separated by semicolon

example:


if you have any problem then write comment.

now you are ready to start enjoy :)





Wednesday, 9 April 2014

write a program to implement queue using linked list.
#include<stdio.h>
#include<stdlib.h>
void insertion();
void display();
void create_node();
void deletion();
struct link_list
{
  int data;
  struct link_list *next;
}*start=NULL;
typedef struct link_list node;
node *current,*nnew,*temp;
int main()
 {
  int a;
  char ch;
   do
   {
    printf("\n enter your choice\n\n1->insertion\n2->display\n3->deletion\n");
    scanf("%d",&a);
    switch(a)
      {
      case 2:
      display();
       break;
      case 1:
       {
        insertion();
        }
         break;
      case 3:
       {
        deletion();
       }
        break;
      default:
        printf("wrong choice");
     }
    printf("\n \n press any key to continue and press n to quit->");
    scanf("%s",&ch);
   }while(ch!='n');
 return 0;
 }

void insertion()
{
 int i=0;
 printf("\nhow many nodes you want to create->");
 scanf("%d",&i);
 while(i!=0)
  {
  if(start==NULL)
   {
    create_node();
    start=nnew;
    current=start;
    printf("\tnode inserted successfully\n");
   }
  else
    {
       current=start;
       while(current->next!=NULL)
       {
       current=current->next;
       }
       create_node();
       current->next=nnew;
       current=nnew;
       printf("\tinserted successfully\n");
     }
   i--;
  }
}
void create_node()
{
       int k;
       nnew=malloc(sizeof(node));
       nnew->next=NULL;
       printf("enter the data for this node->");
       scanf("%d",&k);
       nnew->data=k;
}
void display()
{
       int c=0,i;
       current=start;
       while(current!=NULL)
{c++;
       current=current->next;
}
   for(i=0;i<c;i++)
   printf("=====");
   printf("\n");
   current=start;
while(current!=NULL)
{
   printf("%d | " ,current->data);
   current=current->next;
}
   printf("\n");
 for(i=0;i<c;i++)
  printf("=====");
}

void deletion()
{
       int d,i;
       printf("enter how many element you want to delete->");
       scanf("%d",&d);
       for(i=0;i<d;i++)
       {
       if(start==NULL)
       {
              start=NULL;
     printf("Queue is empty\n");
       }
       Else
     {
      temp=start;
      start=start->next;
      free(temp);
      printf("data is deleted");
     }
  }
}



write a programme of stack using linked list.
#include<stdio.h>
#include<stdlib.h>
void display(void);
void push(void);
void pop(void);
struct link_list
{
int data;
struct link_list *next;
}*start=NULL;
typedef struct link_list node;
node *current,*nnew;

int main()
{
int a;
char ch;
do
{
printf("\n enter your choice\n1->push\n2->pop\n3->display\n");
scanf("%d",&a);
switch(a)
{
case 3:
display();
break;
case 2:
       pop();
       break;
case 1:
push();
break;
default:
printf("wrong choice");
}
printf("\n press any key to continue and press n to quit->");
scanf("%s",&ch);
}while(ch!='n');
return (0);
}

void push(void)
{
int i=0,k;
printf("how many elements you want to enter->");
scanf("%d",&i);
while(i!=0)
{
nnew=malloc(sizeof(node));
nnew->next=NULL;
if(start==NULL)
{
printf("enter any integer data->");
scanf("%d",&k);
nnew->data=k;
start=nnew;
current=start;
printf("\t%d pushed successfully\n",start->data);
}
else
{
printf("enter any integer data->");
scanf("%d",&k);
nnew->data=k;
nnew->next=start;
start=nnew;
printf("\t%d pushed successfully\n",start->data);
}
i--;
}
}

void display(void)
{
              current=start;
              printf("\n");
              while(current!=NULL)
              {
              printf("\t%d\n" ,current->data);
              current=current->next;
       }
}
void pop(void)
{
       int count=0;
       printf("how many elements you want to pop->");
       scanf("%d",&count);
       current=start;
       while(count!=0)
       {
       if(start==NULL)
              printf("stack underflow!");
              else
              {
       printf("%d popped successfully\n",start->data);
       current=start;
start=start->next;
free(current);
}
       count--;
}

} 




Tuesday, 8 April 2014

/*write a program to implement merge sort*/
#include<stdio.h>
#define MAX 50

void mergeSort(int arr[],int low,int mid,int high);
void partition(int arr[],int low,int high);

int main(){

    int merge[MAX],i,n;

    printf("Enter the total number of elements: ");
    scanf("%d",&n);

    printf("Enter the elements which to be sort: ");
    for(i=0;i<n;i++){
         scanf("%d",&merge[i]);
    }

    partition(merge,0,n-1);

    printf("After merge sorting elements are: ");
    for(i=0;i<n;i++){
         printf("%d ",merge[i]);
    }

   return 0;
}

void partition(int arr[],int low,int high){

    int mid;

    if(low<high){
         mid=(low+high)/2;
         partition(arr,low,mid);
         partition(arr,mid+1,high);
         mergeSort(arr,low,mid,high);
    }
}

void mergeSort(int arr[],int low,int mid,int high){

    int i,m,k,l,temp[MAX];

    l=low;
    i=low;
    m=mid+1;

    while((l<=mid)&&(m<=high)){

         if(arr[l]<=arr[m]){
             temp[i]=arr[l];
             l++;
         }
         else{
             temp[i]=arr[m];
             m++;
         }
         i++;
    }

    if(l>mid){
         for(k=m;k<=high;k++){
             temp[i]=arr[k];
             i++;
         }
    }
    else{
         for(k=l;k<=mid;k++){
             temp[i]=arr[k];
             i++;
         }
    }

    for(k=low;k<=high;k++){
         arr[k]=temp[k];
    }
}