C Programming Tutorial

 
 
 

Advanced Programming

Array

One dimensional array Two dimensional Array Two dimensional array pointers Array of pointers Print array Print Array - for loop Print array in reverse Print address array - for loop Multidimentional array - function Print address array - pointers Print reverse string of array Print array ascii value-without atoi Character array - upper case Multiplication table - 2D array Passing array to function Max or greatest value in array Merge sorted array Array of structure Array of pointers to string Array within a structure

String Programs

Copy string Substring of string String concatination Vowel in string Swap char in string Palindrome string Rotate string Bubble sort of strings Sorting of words Encode decode string Compress string

File Programs

Read write in 2 files Add,edit,delete,search in file Add,search using structure Append in file Merge file Count word,line,char in file Count record - struct fread() example fwrite() example fopen() example fclose() example fscanf() and fprintf() fseek() example Error handling in file op Find odd,even num Odd even numbers in file Max, min age in class Random numbers file Preprocessor in 2 files Encode decode in file

Bios Programming

biosequip( ) - sys confi biosdisk( ) - partition tbl info Pc type-bios data area File allocation table Telephone directory

TSR Programming

Interchange letters Interchange letters on screen Unload TSR on key press-keyboard Unload TSR - timer interrupt Activate, deactivate TSR Print alphabet from printer Repeat key press Keep caps on Make ctrl, alt key pressed

Interrupt Programming

Restart computer Conventional memory of sys Save IVT in file Print string-interrupt 21h Read char-interrupt 21h Read char with echo-interrupt 21h Delete file-interrupt 21h Delete directory-interrupt 21h Get set system date Show system configuration Search, delete file in dir Display multiple file in dir

Mouse Programming

Text mode mouse handling Graphics mode mouse handling Double click of mouse
 
 
 # include <graphics.h>
 # include    <conio.h>
 # include      <dos.h>

 const int InitMouse( );

 void ShowMouseCursor( );
 void HideMouseCursor( );

 void SetMousePosition(int x,int y);
 void GetMousePosition(int *x,int *y);

 void SetMouseHorizontalRange(int x_min,int x_max);
 void SetMouseVerticalRange(int y_min,int y_max);
 void SetMouseRange(int x_min,int y_min,int x_max,int y_max);

 const int LeftMouseKeyPressed( );
 const int RightMouseKeyPressed( );

 void show_border( );


 int main( )
 {
    int x_cord;
    int y_cord;

    int prev_x_cord;
    int prev_y_cord;

    int gdriver=DETECT;
    int gmode;
    int errorcode;

    initgraph(&gdriver,&gmode,\"..\\\\Bgi\");

    errorcode=graphresult( );

    if(errorcode!=grOk)
    {
       printf(\"Graphics Error: %s\\n\",grapherrormsg(errorcode));
       printf(\"\\nPress any key to exit...\");

       getch( );
       exit(1);
    }

    if(!InitMouse( ))
    {
       printf(\"Fatal Error : Unable to detect the Mouse.\");
       printf(\"\\nPress ANY key to exit...\");

       getch( );
       exit(1);
    }

    show_border( );

    ShowMouseCursor( );
    SetMousePosition((getmaxx( )/2),(getmaxy( )/2));
    SetMouseRange(16,41,613,436);

    gotoxy(1,30);
    printf(\"Note: Press ANY key to exit.\");

    do
    {
       GetMousePosition(&x_cord,&y_cord);

       if(x_cord!=prev_x_cord || y_cord!=prev_y_cord)
       {
      gotoxy(1,1);
      printf(\"Current Mouse Coordinates : ( x=%u , y=%u ) \",x_cord,y_cord);

      prev_x_cord=x_cord;
      prev_y_cord=y_cord;
       }

       if(LeftMouseKeyPressed( ))
       {
      gotoxy(1,2);
      printf(\"*** Left Mouse Key Pressed\");

      while(LeftMouseKeyPressed( ));

      gotoxy(1,2);
      printf(\"                           \");
       }

       if(RightMouseKeyPressed( ))
       {
      gotoxy(1,2);
      printf(\"*** Right Mouse Key Pressed\");

      while(RightMouseKeyPressed( ));

      gotoxy(1,2);
      printf(\"                           \");
       }
    }
    while(!kbhit( ));

    getch( );
    return 0;
 }


 //--------------------------  show_border( )  ---------------------------//


 void show_border( )
 {
    int i;

    gotoxy(2,3);
    printf(\"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\");

    for(i=0;i<25;i++)
    {
       gotoxy(2,(4+i));
       printf(\"º                                                                            º\");
    }

    gotoxy(2,29);
    printf(\"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\");
 }


 //---------------------------  InitMouse( )  ----------------------------//


 const int InitMouse( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0000;

    int86(0x33,&InReg,&OutReg);

    if(OutReg.x.ax==0x0000 && OutReg.x.bx==0xFFFF)
       return 0;

    return 1;
 }


 //-------------------------  ShowMouseCursor( )  ------------------------//


 void ShowMouseCursor( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0001;

    int86(0x33,&InReg,&OutReg);
 }


 //-------------------------  HideMouseCursor( )  ------------------------//


 void HideMouseCursor( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0002;

    int86(0x33,&InReg,&OutReg);
 }


 //------------------------  SetMousePosition( )  ------------------------//


 void SetMousePosition(int x,int y)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0004;
    InReg.x.cx=x;
    InReg.x.dx=y;

    int86(0x33,&InReg,&OutReg);
 }


 //-------------------------  GetMousePosition( )  -----------------------//


 void GetMousePosition(int *x,int *y)
 {
    union REGS InReg;
    union REGS OutReg;

    *x=0;
    *y=0;

    InReg.x.ax=0x0003;

    int86(0x33,&InReg,&OutReg);

    *x=OutReg.x.cx;
    *y=OutReg.x.dx;
 }


 //----------------------  SetMouseHorizontalRange( )  -------------------//


 void SetMouseHorizontalRange(int x_min,int x_max)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0007;
    InReg.x.cx=x_min;
    InReg.x.dx=x_max;

    int86(0x33,&InReg,&OutReg);
 }


 //----------------------  SetMouseVerticalRange( )  ---------------------//


 void SetMouseVerticalRange(int y_min,int y_max)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0008;
    InReg.x.cx=y_min;
    InReg.x.dx=y_max;

    int86(0x33,&InReg,&OutReg);
 }


 //--------------------------  SetMouseRange( )  -------------------------//


 void SetMouseRange(int x_min,int y_min,int x_max,int y_max)
 {
    SetMouseVerticalRange(y_min,y_max);
    SetMouseHorizontalRange(x_min,x_max);
 }


 //----------------------  LeftMouseKeyPressed( )  -----------------------//


 const int LeftMouseKeyPressed( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0003;

    int86(0x33,&InReg,&OutReg);

    return ((OutReg.x.bx==0x0001)?1:0);
 }


 //----------------------  RightMouseKeyPressed( )  ----------------------//


 const int RightMouseKeyPressed( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0003;

    int86(0x33,&InReg,&OutReg);

    return ((OutReg.x.bx==0x0002)?1:0);
 }

 
 
Didn't find what you were looking for? Find more on Program to show the Basic Mouse Handling in Graphics Mode