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 <stdlib.h>
 # include  <stdio.h>
 # include  <conio.h>
 # include   <bios.h>

 struct Partition
 {
    unsigned char ucBootable;
    unsigned char ucStartHead;
    unsigned int  uiStartCylinderSector;
    unsigned char ucTypeOfPartition;
    unsigned char ucEndHead;
    unsigned int  uiEndCylinderSector;
    unsigned long ulStartSector;
    unsigned long ulPartitionLength;
 };


 int main( )
 {
    unsigned char sBuffer[512]={NULL};

    clrscr( );
    textmode(BW80);

    biosdisk(2,0x80,0,0,1,1,sBuffer);

    if((_AH&0xFF)!=0x00)
    {
       switch(_AH)
       {
      case 0x01 : printf(\"Bad command\");
              break;

      case 0x02 : printf(\"Address mark not found\");
              break;

      case 0x03 : printf(\"Attempt to write to write-protected disk\");
              break;

      case 0x04 : printf(\"Sector not found\");
              break;

      case 0x05 : printf(\"Reset failed (hard disk)\");
              break;

      case 0x06 : printf(\"Disk changed since last operation\");
              break;

      case 0x07 : printf(\"Drive parameter activity failed\");
              break;

      case 0x08 : printf(\"Direct memory access (DMA) overrun\");
              break;

      case 0x09 : printf(\"Attempt to perform DMA across 64K boundary\");
              break;

      case 0x0A : printf(\"Bad sector detected\");
              break;

      case 0x0B : printf(\"Bad track detected\");
              break;

      case 0x0C : printf(\"Unsupported track\");
              break;

      case 0x10 : printf(\"Bad CRC/ECC on disk read\");
              break;

      case 0x11 : printf(\"CRC/ECC corrected data error\");
              break;

      case 0x20 : printf(\"Controller has failed\");
              break;

      case 0x40 : printf(\"Seek operation failed\");
              break;

      case 0x80 : printf(\"Attachment failed to respond\");
              break;

      case 0xAA : printf(\"Drive not ready (hard disk only)\");
              break;

      case 0xBB : printf(\"Undefined error occurred (hard disk only)\");
              break;

      case 0xCC : printf(\"Write fault occurred\");
              break;

      case 0xE0 : printf(\"Status error\");
              break;

      case 0xFF : printf(\"Sense operation failed\");
              break;

      default   : printf(\"Unknown Error\");
       }
    }

    else
    {
       struct Partition *ptrDriveC=(struct Partition*)&sBuffer[0x1BE];

       int iStartingCylinderHighByte=(ptrDriveC->uiStartCylinderSector>>8);
       int iStartingCylinderLowByte=((ptrDriveC->uiStartCylinderSector&0x00C0)<<2);
       int iStartingCylinder=(iStartingCylinderLowByte+iStartingCylinderHighByte);

       int iEndingCylinderHighByte=(ptrDriveC->uiEndCylinderSector>>8);
       int iEndingCylinderLowByte=((ptrDriveC->uiEndCylinderSector&0x00C0)<<2);
       int iEndingCylinder=(iEndingCylinderLowByte+iEndingCylinderHighByte);

       printf(\"* * * * * * * * * *  Partition Information  * * * * * * * * * *\\n\\n\");
       printf(\"Drive C: \");

       if(ptrDriveC->ucBootable==0x80)
      printf(\"Bootable\\n\");

       else
      printf(\"Not Bootable\\n\");

       printf(\"Start Head = %d\\n\",ptrDriveC->ucStartHead);
       printf(\"Starting Sector Number = %d\\n\",(ptrDriveC->uiStartCylinderSector&0x003F));
       printf(\"Starting Cylinder Number = %d\\n\",iStartingCylinder);

       printf(\"Partition Type = \");

       switch(ptrDriveC->ucTypeOfPartition)
       {
      case 0x00 : printf(\"Unused\\n\");
              break;

      case 0x01 : printf(\"12-Bit\\n\");
              break;

      case 0x02 : printf(\"Xenix\\n\");
              break;

      case 0x04 : printf(\"16-Bit\\n\");
              break;

      case 0x05 : printf(\"Extends\\n\");
              break;

      case 0x06 : printf(\"Huge\\n\");
              break;

      case 0x64 : printf(\"Novell\\n\");
              break;

      case 0x75 : printf(\"PCIX\\n\");
              break;

      case 0xDB : printf(\"CP/M\\n\");
              break;

      case 0xFF : printf(\"BBT\\n\");
              break;

      default   : printf(\"UnKnown\\n\");
              break;
       }

       printf(\"End Head = %d\\n\",ptrDriveC->ucEndHead);
       printf(\"Ending Sector Number = %d\\n\",(ptrDriveC->uiEndCylinderSector&0x003F));
       printf(\"Ending Cylinder Number = %d\\n\",iEndingCylinder);
       printf(\"Start Sector relative to Disk Begining = %ld\\n\",ptrDriveC->ulStartSector);
       printf(\"Partition Length = %ld\\n\",ptrDriveC->ulPartitionLength);

       printf(\"\\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\");
    }

    getch( );
    return 0;
 }