C and C++ Programming Resources

Custom Search

UTILITIES

IT IS A MULTIFUNCTIONAL PROGRAMS,WHICH HAVE A LOTS OF OPTION.IN THIS HINDI EDITOR IS STILL NOT COMPLETED.I AM WORKING ON IT.WHEN I COMPLETE I WILL MAIL IT TO YOU.

/*******************************************************
*     MYCPLUS Sample Code - http://www.mycplus.com     *
*                                                     *
*   This code is made available as a service to our   *
*      visitors and is provided strictly for the      *
*               purpose of illustration.              *
*                                                     *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/

#include
#include
#include    //THIS FILE IS FOR INCLUDE REGS
#include//THIS WILL INCLUDE MALLOC FUNCTION
#include

char far *vid_mem;
int m,n,*p,i,n1,j,num;
int scan,ascii,array[50],array1[50],final[50];
int simple,simple1;
char *mainmenu[]={"DATA STRUCTURE SERVICES" ,
		  "HINDI EDITOR",
		  "DIRECTORY SERVICES",
		  "FILE RELATED SERVICES",
		  "MISCELLANEOUS",
		  "EXIT"};

char *datastruct[]={"SEARCHING",
		    "SORTING",
		    "RETURN TO MAIN MENU"};

char *searching[]={"LINEAR SEARCH",
		   "BINARY SEARCH",
		   "RETURN TO MAIN MENU"
		   };

char *sorting[]={"BUBBLE SORT",
		"SELECTION SORT",
		"INSERTION SORT",
		"QUICK SORT" ,
		"MERGE SORT",
		"RETURN TO MAIN MENU"
		};

char *directoryrelated[]={ "CREATE A FOLDER",
			   "DELETE A FOLDER",
			   "CHANGE DIRECTORY",
			   "RETURN TO MAIN MENU"
			 };

char *filemenu[]=  { "COPY FILE",
			 "DELETE FILE",
			 "RENAME FILE",
			 "ENCRYPT FILE",
			 "DECRYPT FILE",
			 "RETURN TO MAIN MENU"
		       };

char *documentation[]={"THEORY",
		     "PRACTICLE",
		     "RETURN TO MAIN MENU"
		    };

int a[4][4]={ 5,7,9,11,
	      4,6,12,3,
	      1,8,15,2,
	      10,13,14,0
	    };

void initialmenu();
void  write2vdu(int,int,char ,int);//THIS WILL WRITE IN VDU MEMORY
void screen();
void whitescreen(int,int,int,int);
void popupmenu(char **,int,int,int);     //FUNCTION PROTOTYPE
void write2vdustring(int,int,char *,int);//THIS IS FOR IF WE PASS A STRING DIRECT TO IT
void getkey();
int getresponse(char **,int,int,int,int);  //FUNCTION PROTOTYPE
void datastructservices();   //TO SHOW DATA STRUCTURE RELATED SERVICES
void searchingservices();    //TO SHOW SEARCHING OPTION
void sortingservices();
void linearsearch();
void theorypracmenu();
void read_array();
void search_number();
void printresult();
void binarysearch();
void checkorder();
void bubblesort();
void display();
void selectionsort();
void insertionsort();
void quicksort();
void quick_sort(int,int,int);
void partition(int,int,int*);
void shellsort();
void merge_sort();
void read_mer();
void directoryservices();
void makedir();
void changedir();
void deletedir();
void filerelatedservices();
void copyfile();
void deletefile();
void renamefile();
void encryptfile();
void decryptfile();
void miscell();
void displaynuminbox();
void end();
int without_scan();

void main()
{
	int item;//IT IS FOR GETTING FOR MAIN SWITCH STATEMENTS

	vid_mem=(char far *)0xb8000000L; //ADDRESS FOR CGA
	initialmenu();

	while(1)
	{
	  item=getresponse(mainmenu,7,20,6,17); //THIS WILL PERFORM RESPONSE CORRESPONDING TO THAT KEY IS HIT

	  switch(item)
	{
	  case 1:
	  datastructservices();
	  break;

	  case 3:
	  directoryservices();
	  break;

	  case 4:
	  filerelatedservices();
	  break;

	  case 5:
	  miscell();
	  break;

	  case 6:
	  case 27: //ASCII VALUE OF ESC
	  exit(1);
	  break;
	}

      }

}

void initialmenu()
{
	clrscr();
	screen();  //THIS WILL DRAW A SIMPLE BACKGROUND SCREEN
	whitescreen(5,18,19,58);//STARTING ROW,STARTING COL,ENDING ROW,ENDING COL
	popupmenu(mainmenu,7,20,5); //THIS WILL GIVE MENU
	  //	getkey();//THIS WILL RECEIVE KEY FROM KEYBOARD
}


void write2vdu(int r,int c,char ch,int attri )
{
char far *v;
v=vid_mem+r*160+c*2;
*v=ch;
v++;
*v=attri;
}


void screen()
{
  int r,c;
    for(r=0;r<=24;r++)
      {
	for(c=0;c<=79;c++)
	  {
	    write2vdu(r,c,' ',90); //90 IS USED FOR PINK BACKGROUND
	  }
      }
}
void whitescreen(int startrow,int startcol,int endrow,int endcol)
{
int r,c;
     for(r=startrow;r<=endrow;r++)
      {
	for(c=startcol;c<=endcol;c++)
	  {
	    write2vdu(r,c,' ',112); //112 WILL TURN IT TO WHITE
	  }
      }
}
void popupmenu(char **commainmenu,int r,int c,int count)
{
     int i,temp;
     temp=r;

      for(i=0;i<=count;i++)
       {
	 write2vdustring(r,c,commainmenu[i],112);
	 r=r+2;
	}
       write2vdustring(temp,c,commainmenu[0],96);//TO MAKE FIRST ROW HIGHLIHHTED
}

void write2vdustring(int r,int c,char *ch ,int attri)
{
   while(*ch!=NULL)
   {
     write2vdu(r,c,*ch,attri);
     ch++;
     c++;
    }
}

void getkey()
{
    union REGS i,o;
    while(!kbhit());
    i.h.ah=0;  //SERVICE NUMBER TO FETCH ASCII & SCAN CODE
    int86(22,&i,&o);
    scan= o.h.ah; //CALCULATES SCAN CODE VALUES
    ascii=o.h.al;  //CALCULATES ASCII CODE  VALUES
}

int getresponse(char **commainmenu,int r,int c,int count,int endrow)
{
  int  i=1,temp; //i IS TO INCREASE THE ARRAY ELEMNT
  temp=r;       //INITIAL VALUE IS STORED IN TEMPARORY VARIABLE
 while(1)
 {
   getkey();
 if(ascii==0)
 {
    switch(scan)
       {
	       case 80://SCAN CODE FOR DOWN ARROW KEY
	       write2vdustring(r,c,commainmenu[i-1],112); //TO MAKE PRVIOUS ROW NORMAL
	       i++;
	       r=r+2;  //NEXT ROW IS 2 ROWS AHEAD OF FIRST
	       break;

	       case 72: //SCAN CODE FOR UPWARD ARROW KEY
	       write2vdustring(r,c,commainmenu[i-1],112);  //TO MAKE PRVIOUS ROW NORMAL
	       r=r-2;
	       i=i-1;
	       break;
       }

	 if(i>count)//IF DOWNWARD KEY IS PRESSED ON LAST ITEM
	   {
	     i=1; //REINITIALAZATION
	     r=temp;
	   }

	 if(i==0)  //IF UPWARD KEY IS PRESSED ON FIRST ITEM
	 {
	   i=count;
	   r=endrow;
	   }

	   write2vdustring(r,c,commainmenu[i-1],96);//TO MAKE NEXT & PREVIOUS ROW HIGHLIGHTED

   }
  else
     if(ascii==13)  //ASCII VALUE OF ENTER IS 13
	return(i);   //RETURN THAT ITEM WHICH WE PRESSED ENTER

     if(ascii==27)
     return 27;

}
 }



void  datastructservices()
  {
	  int datast; //IT IS FOR GETTING  DATA STRUCTURE SWITCH
	  clrscr();
	  screen();   //GIVES A BACKGROUND SCREEN
	  whitescreen(7,25,15,50);
	  write2vdustring(20,21,"ENTER WHAT DO YOU WANT TO DO",112);
	  write2vdustring(20,49," OR PRESS ECS FOR MAIN MENU",112);
	  popupmenu(datastruct,8,27,2);  //OPTION FOR DATA STRUTURE

	  datast=getresponse(datastruct,8,27,3,12);

	  switch(datast)
	  {
	    case 1:
	    searchingservices();
	    break;

	    case 2:
	    sortingservices();
	    break;

	    case 3:
	    case 27:
	    initialmenu();
	    break;

	}
  }

void  searchingservices()
{
	    int search;
	    clrscr();
	    screen();
	    whitescreen(8,23,14,50);
	    popupmenu(searching,9,24,2);

	    search=getresponse(searching,9,24,3,13);

	    switch(search)
	    {
	    case 1:
	    linearsearch();
	    searchingservices();
	    break;

	    case 2:
	    binarysearch();
	    searchingservices();
	    break;

	    case 3:
	    case 27:
	    initialmenu();
	    break;


}      }

void sortingservices()
{
     int sort;
     clrscr();
     screen();
     whitescreen(5,18,19,58);
     popupmenu(sorting,6,19,5);
     sort=getresponse(sorting,6,19,6,16);

     switch(sort)
     {
     case 1:

     bubblesort();
     datastructservices();
     break;

     case 2:
     selectionsort();
     datastructservices();
     break;

     case 3:
     insertionsort();
     datastructservices();
     break;

     case 4:
     quicksort();
     datastructservices();
     break;

     case 5:
     merge_sort();
     datastructservices();
     break;

     case 6:
     case 27:
     initialmenu();
     break;
     }
}
void end()
{
int ai,aj,ak,al;
//clrscr();
//screen();
textmode(1);
	for( ai=0,aj=0, ak=34,al=33;ai<10,aj<17,ak>10,al>17;ai++,aj++,ak--,al--)
	{
		clrscr();

		gotoxy(ai-1, 8);
		textbackground(1);
	       //	textcolor(15);
		printf( "   Thanks   ");

		gotoxy(aj, 16);
		printf( "   This");

		gotoxy(ak-4, 12);
		printf ( " For using");

		gotoxy(al-2, 20);
		printf ( " Project");
		delay(200);
	  }
								//end of for loop
	  gotoxy(9, 9);
	  printf ( " **********************");

	  gotoxy(9, 13);
	  printf ( " **********************");

	  gotoxy(9, 17);
	  printf ( " **********************");
	  gotoxy(12, 21);
	  printf (" ***************");
	  delay(2000);

	 // textmode(2);
	//  textbackground(0);
	  //textcolor(5);
}     // end of function


void linearsearch()
{
     FILE *fp;
     char ch;
     int item;
     theorypracmenu();
    item=getresponse(documentation,8,27,3,12);


    switch(item)
    {

     case 1:
     screen();
     fp=fopen("doc.c","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
      }
     fclose(fp);
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    break;

    case 2:
    read_array();
    search_number();


     for(i=0;i=simple-1)
	   {
	     printresult();
	     printf("Element not found");
	     write2vdustring(21,26,"RESULT OF LINEAR SEARCH",112+128);//112 IS FOR WHITE BACKGROUND & 128 IS FOR BLINKING CHARACTERS
	    }
	}
	getch();
	break;

	case 3:
	break;
    }
}

void theorypracmenu()
{
    screen();
    whitescreen(7,25,15,50);
    popupmenu(documentation,8,27,2);  //OPTION FOR PRACTICLE & THEORY
}

void read_array()
  {
     //  int a[10],i;
     clrscr();
     screen();
     gotoxy(20,4);
     printf("Enter how many numbers  [   ]");
     gotoxy(45,4);
    simple=without_scan();

      if(simple<=15)
      {
     p= (int*)malloc(simple*sizeof(int));


     gotoxy(8,6);
     printf("INPUT ARRAY");
     gotoxy(8,7);
     printf("*************");

     for(i=0;i=48 && m<=57)
	       {
		  count++;
		  n=m-48;
		 // if(n=='\b')
	       //	 write2vdustring(45,3," ",120);
		 // pt=(int *)malloc(n*sizeof(int));
		  printf("%d",n);
		  pt[i]=n;
		  i++;
		}
	  }
	     if(ch==13 && count!=0)
	     {
	       pt[i]='\0';
		break;
	     }
       }
       var=0;
       i--;   //I VALUE IS ON NULL TERMINATOR SO IT IS DECRESED BY ONE

       for(j=0;i>=0;j++,i--)
	 var=var+(pt[i]*pow(10,j));
	 return(var);


}

void search_number()
{
   gotoxy(20,4);
   printf("Enter no to be searched [   ]");
   gotoxy(45,4);
   n1=without_scan();
}

void printresult()
{
   gotoxy(47,6);
   printf("OUTPUT ARRAY");
   gotoxy(47,7);
   printf("*****************");
   gotoxy(49,9);
}

void binarysearch()
{
   int startpos=1,endpos,mid,loc;
   int item;
   FILE *fp;
   char ch;
   theorypracmenu();
   item=getresponse(documentation,8,27,3,12);

   switch(item)
   {
   case 1:
   screen();
     fp=fopen("binary.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
    // break;
     }
     write2vdustring(24,30,"PRESS ANY KEY",112);
    fclose(fp);
    free(fp);
    getch();

      screen();
     fp=fopen("bin.txt","r");

     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);

     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    break;

    case 2:
   read_array();
   search_number();

   for(i=0;ip[i+1])
      {
	write2vdustring(23,31,"ARRAY IS NOT IN SORTED ORDER ",112+128);
	write2vdustring(24,31," &  THE  SORTED  ARRAY  IS   ",112+128);
	delay(1600);
	screen();
	bubble_sort();

      }

   }

   endpos=simple;
   mid=(startpos+endpos)/2;

	while (startpos<=endpos && p[mid] != n1)
	{
	 if (p[mid]n1) endpos = mid-1;
	 mid = (startpos+endpos)/2;
	}
      gotoxy(10,10);
      if(p[mid]==n1)
      {
	 printresult();
	 gotoxy(25,24);
	 printf("NUMBER FOUND AT LOCATION %d",mid+1);
      }
      else
      {
	 printresult();
	 gotoxy(25,24);
	 printf("NUMBER NOT FOUND");
      }

    // free(p);
     getch();
     break;

     case 3:
     case 27:
     break;
   }
}

void bubblesort()
{
   int temp;
   int item;
   FILE *fp;
   char ch;
   theorypracmenu();
   item=getresponse(documentation,8,27,3,12);

   switch(item)
   {
   case 1:
   screen();
     fp=fopen("bub1.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    fclose(fp);
    free(fp);


    screen();
     fp=fopen("bub.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    fclose(fp);
    free(fp);
    break;

    case 2:
     read_array();
   for(j=0;jp[i+1])
		 {
		    temp=p[i];
		    p[i]=p[i+1];
		    p[i+1]=temp;
		 }
	   }

      }
printresult();
display();
write2vdustring(21,26,"RESULT OF BUBBLE  SORT",112+128);//112 IS FOR WHITE BACKGROUND & 128 IS FOR BLINKING CHARACTERS
getch();
break;

case 3:
case 27:
break;
}
}
bubble_sort()
{
int temp;
for(j=0;jp[i+1])
		 {
		    temp=p[i];
		    p[i]=p[i+1];
		    p[i+1]=temp;
		 }
	   }

      }
      display();
      return(0);

}

void display()
{
  int row=9;
    for (i = 0; i < simple; i++)
	{
		gotoxy(50, row);
		printf(" %dst Element is  [   ]",i+1);
		if(i<9)
		gotoxy(68, row);
		else
		gotoxy(69,row);
		printf("%d", p[i]);
		row++;
	}

}

void selectionsort()
{
   int temp,j,small,pos;
   int item;
   FILE *fp;
   char ch;
   theorypracmenu();
   item=getresponse(documentation,8,27,3,12);

   switch(item)
   {
   case 1:
   screen();
     fp=fopen("sel1.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    fclose(fp);
    free(fp);

    screen();
     fp=fopen("sel.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    break;

    case 2:
     read_array();
   for (i = 0; i < simple-1; i++)   //simple-1 IS USED BECAUSE WE ARE USING I+1 IN J LOOP
	{
		small= p[i];
		pos = i;

		for( j = i+1 ; j < simple; j++)
		{

			if (p[j] < small)
			{
				small = p[j];
				pos = j;
			}
		}

		if ( pos != i)  //IF SMALLEST ELEMENT IS ON FIRST POSITION
		{
			temp = p[i];
			p[i] = p[pos];
			p[pos] = temp;
		}
	}
	printresult();
	display();
	 write2vdustring(23,26,"RESULT OF SELECTION SORT",112+128);//112 IS FOR WHITE BACKGROUND & 128 IS FOR BLINKING CHARACTERS
	 getch();
	 break;

	 case 3:
	 case 27:
	 break;
    }
}

void insertionsort()
{
  int temp,ptr;
   int item;
   FILE *fp;
   char ch;
   theorypracmenu();
   item=getresponse(documentation,8,27,3,12);

   switch(item)
   {
   case 1:
   screen();
     fp=fopen("ins1.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     {
     printf("%c",ch);
     }
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    fclose(fp);
    free(fp);



     screen();
     fp=fopen("ins1.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     {
     printf("%c",ch);
     }
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
     fclose(fp);
    free(fp);
    break;

    case 2:
   read_array();

    for(i=1;ip[i])
	       {
		 temp=p[i];
		 p[i]=p[j];
		 p[j]=temp;
	       }
	    }
     }

	printresult();
	display();
	 write2vdustring(23,26,"RESULT OF INSERTION SORT",112+128);//112 IS FOR WHITE BACKGROUND & 128 IS FOR BLINKING CHARACTERS
	 getch();
	 break;

	 case 3:
	 case 27:
	 break;
     }
}


void quicksort()
{
      int item;
   FILE *fp;
   char ch;
   theorypracmenu();
   item=getresponse(documentation,8,27,3,12);

   switch(item)
   {
   case 1:
   screen();
     fp=fopen("qui1.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
    fclose(fp);
    free(fp);

    screen();
     fp=fopen("qui.txt","r");
     fseek(fp,0, SEEK_SET);
     while(1)
     {
     ch=fgetc(fp);
     if(ch==EOF)
     break;
     else
     printf("%c",ch);
    // break;
     }
    write2vdustring(24,30,"PRESS ANY KEY",112);
    getch();
     fclose(fp);
    free(fp);
    break;

    case 2:
   read_array();

	// For quick sort
	quick_sort( simple ,0, simple-1);

	printresult();
	display();
	write2vdustring(23,26,"RESULT OF QUICK SORT",112+128);//112 IS FOR WHITE BACKGROUND & 128 IS FOR BLINKING CHARACTERS
	getch();
	break;

	case 3:
	case 27:
	break;
    }
}

// This function performs the partition changing in the array
// by the quick sort method
void quick_sort( int n, int l, int u)
{
	int loc;

	if (l < u)
	{

		partition(l, u, &loc);
		quick_sort(n, l, loc-1);
		quick_sort( n, loc+1, u);

	}
}

// Function to perfrom the partition in the array for quick sort

void partition( int  beg, int end, int *loc)
{
	int first, last, flag, temp;

	*loc = first = beg;

	last = end;
	flag = 0;

	while (!flag)
	{
		while (p[last] >= p[*loc] && (*loc != last))
			last --;

		if (*loc == last)
			flag = 1;
		else
		{

			if (p[*loc] > p[last])
			{

				temp = p[*loc];
				p[*loc] = p[last];
				p[last] = temp;
				*loc = last;

			}
		}

		if (!flag)
		{

			while ((p[first] <= p[*loc]) && (*loc != first))
				first++;

			if (*loc == first)
				flag = 1;
			else
			{
				if (p[*loc] =48)
	      {
		c=30;
		r=r+2;
	       }

       }

  }
}

Tags: ,

There are No Comments to this post. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response or TrackBack from your own site.


Leave a Reply

You must be logged in to post a comment.