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 <string.h>
 # include  <stdio.h>
 # include  <conio.h>
 # include    <dos.h>
 # include    <dir.h>

 void FindFile(const char* Path,const char* FileName);

 const int DeleteFile(const char* File);

 FILE* oFile;

 int file_counter=0;

 int main( )
 {
    char Drive[10]={\"C:\\\\\"};
    char FileName[15]={NULL};
    char CurrentDirectory[MAXPATH]={NULL};

    int cur_drive=getdisk( );

    clrscr( );

    getcwd(CurrentDirectory,MAXPATH);

    printf(\"Enter the File Name to delete: \");
    scanf(\"%s\",FileName);

    printf(\"\\nSearching....\\n\\n\");

    oFile=fopen(\"E:\\\\TC\\\\BIN\\\\Search.txt\",\"wt\");

    fclose(oFile);

    setdisk(2);

    if(getdisk( )==2)
       FindFile(Drive,FileName);

    if(file_counter==0)
       printf(\"No File Found.\");

    else if(file_counter==1)
    {
       char Choice=NULL;
       char Temp[MAXPATH]={NULL};

       oFile=fopen(\"E:\\\\TC\\\\BIN\\\\Search.txt\",\"rt\");

       fgets(Temp,MAXPATH,oFile);

       fclose(oFile);

       Temp[(strlen(Temp)-1)]=NULL;

       printf(\"File Found:: %s\\n\",Temp);
       printf(\"\\nDo you want to delete it? (Y/N) : \");

       Choice=getche( );

       if(Choice==\'Y\' || Choice==\'y\')
       {
      if(DeleteFile(Temp))
      {
         printf(\"\\n\\nUnable to delete the specified file.\");

         getch( );
      }
       }
    }

    else
    {
       int counter=0;
       int file_number=0;

       char Choice=NULL;
       char Temp[MAXPATH]={NULL};

       oFile=fopen(\"E:\\\\TC\\\\BIN\\\\Search.txt\",\"rt\");

       printf(\"The Files Found are ::\\n\");

       for(counter=1;counter<=file_counter;counter++)
       {
      fgets(Temp,MAXPATH,oFile);

      printf(\"%d : %s\",counter,Temp);

      if((counter%15)==0)
      {
         printf(\"\\n Press any key to continue...\");

         getch( );

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

       fclose(oFile);

       printf(\"\\nEnter the File Number to Delete = \");
       scanf(\"%d\",&file_number);

       oFile=fopen(\"E:\\\\TC\\\\BIN\\\\Search.txt\",\"rt\");

       strset(Temp,NULL);

       for(counter=1;counter<=file_number;counter++)
      fgets(Temp,MAXPATH,oFile);

       fclose(oFile);

       Temp[(strlen(Temp)-1)]=NULL;

       printf(\"\\nSelected File :: %s\\n\",Temp);
       printf(\"\\nDo you want to delete it? (Y/N) : \");

       Choice=getche( );

       if(Choice==\'Y\' || Choice==\'y\')
       {
      if(DeleteFile(Temp))
      {
         printf(\"\\n\\nUnable to delete the specified file.\");

         getch( );
      }
       }
    }

    printf(\"\\n\\nPress any key to exit...\");

    setdisk(cur_drive);
    chdir(CurrentDirectory);

    getch( );
    return 0;
 }


 //----------------------------  FindFile( )  ----------------------------//


 void FindFile(const char* Path,const char* FileName)
 {
    struct find_t ffblk;

    int flag;

    char File[MAXPATH]={NULL};

    chdir(Path);

    strcpy(File,Path);
    strcat(File,FileName);

    flag=_dos_findfirst(File,_A_NORMAL,&ffblk);

    if(!flag)
    {
       char Choice;

       while(!flag)
       {
      char Temp[MAXPATH]={NULL};

      strcpy(Temp,Path);
      strcat(Temp,ffblk.name);

      oFile=fopen(\"E:\\\\TC\\\\BIN\\\\Search.txt\",\"at\");

      fputs(Temp,oFile);
      fputs(\"\\n\",oFile);

      fclose(oFile);

      file_counter++;

      flag=_dos_findnext(&ffblk);
       }
    }

    strcpy(File,Path);
    strcat(File,\"*.*\");

    flag=_dos_findfirst(File,FA_DIREC,&ffblk);

    while(!flag)
    {
       if(strcmp(ffblk.name,\".\")!=0 && strcmp(ffblk.name,\"..\")!=0 &&
                              ffblk.attrib==FA_DIREC)
       {
      char Temp[MAXPATH]={NULL};

      strcpy(Temp,Path);
      strcat(Temp,ffblk.name);
      strcat(Temp,\"\\\\\");

      FindFile(Temp,FileName);
       }

       flag=_dos_findnext(&ffblk);
    }

    chdir(Path);
 }


 //---------------------------  DeleteFile( )  ---------------------------//


 const int DeleteFile(const char* File)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.h.ah=0x41;
    InReg.x.dx=FP_OFF(File);

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

    return OutReg.x.cflag;
 }

    Related Post:
  1. Use of break statement in a program

  2. Program of calender

  3. Program to count the total no of characters in one or more character strings by any parallel technique

  4. Program to find the maximum and minimum element in an array using threads

  5. Program to find the sum of numbers from 1 to n using thread

  6. Program to read numbers from two files using fscanf function and write it in another file using fprintf function in ascending order

  7. Program to create processes using fork() and check different states for orphan process

  8. Program to print triangle of numbers as shown in description

  9. Program to read two positive numbers and interchange its values using +(add) and -(sub) operators and without using any extra variable

  10. Find Optimal Time Between Order for a single item is given by TBO = squareroot(2*setup costs/demandrate holding costing peritem unit time)

  11. PROGRAM TO FIND CORRELATION BETWEEN TWO DATA SETS DEFINED NUMBER OF PROCESSES

  12. Program of pay-bill calculations

  13. Program of addition, subtraction,multiplication and division of rational numbers

  14. PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. 1 + 2 + 6 + 24 + 120 + ......

  15. FUNCTION TABULATED AT UNEQUAL INTERVAL

  16. Program of 2-thread for Linux Using the POSIX threads library. Once the thread spawning is done, the first thread should wait for user input

  17. Program to compute area under a curve

  18. PROGRAM FOR MATRIX VECTOR MULTIPLICATION USING INNER LOOP SPLITING FOR N NO.OF PROCESSES

  19. Program to display dimond triangle

  20. FUNCTION XSTRCHR() WHICH SCANS A STRING FROM START TO END IN SEARCH OF A CHARACTER