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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 50


typedef struct
        {
        char  name[10];
        int key;
      } file_record;

/* this function adds the relatiuve addres to the index for a key */
void create_index(long index[], int key, long rel_add )
    {
     index[key] = rel_add;
   }

/* this function writes a record to the file */
void write_rec(FILE *fp, file_record rec)
    {
   fwrite(&rec,sizeof(rec),1,fp);
    }

void main()
    {
       long rel_add;
       int key;
       file_record frec;
       long index[MAX];/* an index list*/
       int n,i;

       FILE *recfile=NULL,*ifile=NULL;
      /* this initializes the index list to all –1 */
       for(i=0; i< MAX; i++)
                index[i]= (-1);

       recfile=fopen(\"mfile\",\"w\");
       if(recfile == NULL)
       {
        printf(\"Error in openeing file mfile\\n\");
        exit(0);
       }
       rel_add = 0 ;
       do
       {
          printf(\" Enter the data vlue and the key of the record to be added to file mfile\\n\");
          scanf(\"%s %d\",frec.name,&frec.key);
            while(index[frec.key] != (-1))
              {
              printf(\" A record with this key value already exist in a file enter record key
   value\\n\");
               scanf(\"%s %d\",frec.name,&frec.key);
              }
             create_index(index,frec.key,rel_add);
             write_rec(recfile,frec);
             rel_add =  ftell(recfile); /* this sets the relative address for the next record to be 
      the value of current file position pointer in bytes from 
      the beginning of the file */
             printf(\"Enter 1 to continue adding records to the file\\n\");
             scanf(\"%d\",&n);
           }while(n == 1);
         ifile=fopen(\"index_file\",\"w\");
         if(ifile == NULL)
           {
                printf(\"Error in openeing file index_file\\n\");
             exit(0);
           }
          fwrite(index,sizeof(index),1,ifile);/*writes the complete index into the index_file */
          fclose(recfile);
          fclose(ifile);
          printf(\"Enter 1 if you want to retrieve a record\\n\");
          scanf(\"%d\",&n);
          if( n == 1)
              {
              ifile=fopen(\"index_file\",\"r\");
              if(ifile == NULL)
                   {
                        printf(\"Error in openeing file index_file\\n\");
                     exit(0);
                }
              fread(index,sizeof(index),1,ifile);/* reads the complete index into the index list 
from the index_file*/
              fclose(ifile);
              recfile=fopen(\"mfile\",\"r\");
              if(recfile == NULL)
                   {
                        printf(\"Error in openeing file mfile\\n\");
                     exit(0);
                }
              }
              printf(\"THE CONTENTS OF FILE IS \\n\");
              while( (fread(&frec,sizeof(frec),1,recfile)) != 0)
                    printf(\"%s %d\\n\",frec.name,frec.key);
              do
              {
                printf(\"Enter the key of the record to be retrieved\\n\");
                scanf(\"%d\",&key);
                rel_add = index[key]; /*gets the relative address of the record from index list */
                if( (fseek(recfile,rel_add,SEEK_SET))!= 0)
                   {
                     printf(\"Error\\n\");
                     exit(0);
                   }
                fread(&frec,sizeof(frec),1,recfile);
                printf(\"The data value of the retrieved record is %s\\n\",frec.name);
                printf(\"Enter 1 if you want to retrieve a record\\n\");
                scanf(\"%d\",&n);
              } while(n == 1);
            fclose(recfile);
          }

    Related Post:
  1. Program to exchange numbers using pointers

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

  3. PROGRAM FOR ARRAY VECTOR MULTIPLICATION

  4. Program to concatenate one linked list at end of another and than to erase all nodes present in the linked list

  5. Functions with no arguments and no return values

  6. FUNCTION TABULATED AT EQUAL INTERVAL USING BACKWARD DIFFERENCE BETWEEN TWO VALUE

  7. PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES.INPUT STEPS FROM KEYBORD.SUM=e1+e2+e3+...(TAKE EXP FUNCTION FROM MATH.H)

  8. Writing strings using %s format

  9. PROGRAM TO FIND SUM OF ALL INTEGER WHICH IS &gt; 100 AND &lt; 200 AND WHICH IS DIVISIBLE BY 7

  10. Doubly circular link list or Circular doubly link list

  11. Program that will accept a line of text from the text file; count the number of words, lines, and characters in the file

  12. Program to read a series of words from a terminal using scanf function

  13. PROGRAM to Search Occurances of Charaters from File in Parallel

  14. Program of bookshop inventory

  15. Program to append one string s2 to another string s1 i.e. concatenation of two strings. (Use strcat function from string.h)

  16. Program to compare one string s2 to another string s1. Print the difference of first unmatched characters (Use strcmp function from string.h)

  17. PROGRAM FOR ADD A CONSTANT TO EACH ARRAY ELEMENETS USING SELF SCHEDULING

  18. Program to display array values using for loop

  19. Program for Number Conversion from Decimal to Binary, Decimal to Octal, Decimal to Hexa, Binary to Octal, Binary to Hexa, Octal to Hexa

  20. Program to calculate average of the elements of an array and then the average deviation using Race condition)

 
 
Didn't find what you were looking for? Find more on Example of file functions like fread(), fwrite(), fopen(), fclose() and fseek()