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
 
 
#define  STUDENTS  5                                             
  #define  SUBJECTS  4                                             
  #include <string.h>                                              

  main()                                                           
  {                                                                
    char name[STUDENTS][20];                                     
    int  marks[STUDENTS][SUBJECTS+1];                    

    printf(\"Input students names & their marks in four subjects\\n\");
    get_list(name, marks, STUDENTS, SUBJECTS);                   
    get_sum(marks, STUDENTS, SUBJECTS+1);                        
    printf(\"\\n\");                                                
    print_list(name,marks,STUDENTS,SUBJECTS+1);                  
    get_rank_list(name, marks, STUDENTS, SUBJECTS+1);            
    printf(\"\\nRanked List\\n\\n\");                                 
    print_list(name,marks,STUDENTS,SUBJECTS+1);  
   }                                                                
/*   Input student name and marks        */                      
       get_list(char *string[ ],                                   
            int array [ ] [SUBJECTS +1], int m, int n)                                       
   {
       int   i, j, (*rowptr)[SUBJECTS+1] = array;                   
       for(i = 0; i < m; i++)                                       
       {                                                            
          scanf(\"%s\", string[i]);                                   
          for(j = 0; j < SUBJECTS; j++)                             
             scanf(\"%d\", &(*(rowptr + i))[j]);                      
       }                                                            
   }
   /*    Compute total marks obtained by each student   */          
   get_sum(int array [ ] [SUBJECTS +1], int m, int n)             
   {                                                                
       int   i, j, (*rowptr)[SUBJECTS+1] = array;                   
       for(i = 0; i < m; i++)                                       
       {
          (*(rowptr + i))[n-1] = 0;                                 
          for(j =0; j < n-1; j++)                                   
             (*(rowptr + i))[n-1] += (*(rowptr + i))[j];            
       }                                                            
   }                                                                


   /*    Prepare rank list based on total marks      */             

   get_rank_list(char *string [ ],                                  
                 int array [ ] [SUBJECTS + 1]                      
                 int m,                                           
                 int n)                                    
   {                                                                
     int i, j, k, (*rowptr)[SUBJECTS+1] = array;                  
     char *temp;                                                  

     for(i = 1; i <= m-1; i++)                                    
        for(j = 1; j <= m-i; j++)                                 
           if( (*(rowptr + j-1))[n-1] < (*(rowptr + j))[n-1])     
           {                                                      
            swap_string(string[j-1], string[j]);                 

            for(k = 0; k < n; k++)                               
            swap_int(&(*(rowptr + j-1))[k],&(*(rowptr+j))[k]); 
             }                                                      
   }                                                                
   /*      Print out the ranked list            */                  
   print_list(char *string[ ],                                   
              int array [] [SUBJECTS + 1],                       
              int m,                                               
              int n)                                       
   {                                                                
       int  i, j, (*rowptr)[SUBJECTS+1] = array;                    
       for(i = 0; i < m; i++)                                       
       {                                                            
          printf(\"%-20s\", string[i]);                               
          for(j = 0; j < n; j++)                                    
             printf(\"%5d\", (*(rowptr + i))[j]);                     
             printf(\"\\n\");                                          
       }                                                            
   }                                                                
   /*     Exchange of integer values              */                
   swap_int(int *p, int *q)                                 
   {                                                                
       int  temp;                                                   
       temp = *p;                                                   
       *p   = *q;                                                   
       *q   = temp;                                                 
   }    




   /*     Exchange of strings         */                            
   swap_string(char s1[ ], char s2[ ])                     
   {                                                                
       char  swaparea[256];                                         
       int   i;                                                     
       for(i = 0; i < 256; i++)                                     
          swaparea[i] = \'\\0\';                                       
       i = 0;                                                       
       while(s1[i] != \'\\0\' && i < 256)                              
       {                                                            
          swaparea[i] = s1[i];                                      
          i++;                                                      
       }                                                            
       i = 0;                                                       
       while(s2[i] != \'\\0\' && i < 256)                              
       {                                                            
          s1[i] = s2[i];                                            
          s1[++i] = \'\\0\';                                           
       }                                                            
       i = 0;                                                       
       while(swaparea[i] != \'\\0\')                                   
       {                                                            
          s2[i] = swaparea[i];                                      
          s2[++i] = \'\\0\';                                           
       }                                                            
   }                                                                

Output                                                           

   Input students names & their marks in four subjects              
   S.Laxmi 45 67 38 55                                              
   V.S.Rao 77 89 56 69                                              
   A.Gupta 66 78 98 45                                              
   S.Mani 86 72 0 25                                                
   R.Daniel 44 55 66 77                                             
   S.Laxmi                45   67   38   55  205                    
   V.S.Rao                77   89   56   69  291                    
   A.Gupta                66   78   98   45  287                    
   S.Mani                 86   72    0   25  183                    
   R.Daniel               44   55   66   77  242                    

   Ranked List                                                      
   V.S.Rao                77   89   56   69  291                    
   A.Gupta                66   78   98   45  287                    
   R.Daniel               44   55   66   77  242                    
   S.Laxmi                45   67   38   55  205                    
   S.Mani                 86   72    0   25  183