C Programming Tutorial

 
 
 
 
#include <alloc.h>
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#define UL unsigned long
#define UI unsigned int
#define UC unsigned char
//+-+-+-+-+-+-+-+-+-+-+-+-+-+< BMP Structures >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
typedef struct
{
    char Type[2];
    UL Size;
    UI R1;
    UI R2;
    UL OffSet;
}BMP1;
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
typedef struct
{
    UL headsize;
    UL Hlen;
    UL Vlen;
    UI planes;
    UI BPP;
    UL Method;
    UL BmpSize;
    UL HRes;
    UL VRes;
    UL Colors;
    UL IColors;
}BMP2;
//+-+-+-+-+-+-+-+-+-+-+-+-+-< Display BMP >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
int ShowBMP(int x, int y, char* FileName)
{
      int b,a;
      BMP1 Obj1;
      BMP2 Obj2;
      UC * Holder;
      int in=0;
      UC c=0;
      FILE * fp;

      fp = fopen(FileName,\"rb\");
      if(fp==NULL)
          return 0;
      fread(&Obj1, sizeof(Obj1), 1, fp);
      fread(&Obj2, sizeof(Obj2), 1, fp);
      if(Obj2.BPP!=4)  // This isn\'t a 16 color bmp we can read;
      {
        fclose(fp);
        return 0;
      };
      fseek(fp,Obj1.OffSet,SEEK_SET);
      Holder=(UC *) calloc(Obj2.Hlen/2+1, sizeof(UC));
      for(b=Obj2.Vlen;b>=0;b--)
      {
        fread(Holder, sizeof(UC), Obj2.Hlen/2, fp);
        c=0;
        in=0;
        for(a=0;a<=Obj2.Hlen;a+=2)
        {
            c = (Holder[in] | 0x00) >>4;
            putpixel(a+x,b+y,c);
            c = (Holder[in] | 0xF0) & 0x0F;
            putpixel(a+1+x,b+y,c);
            in++;
        }
      }
      free (Holder);
      fclose(fp);
      return 1;
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-< **** >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Two bmp demo.bmp & demo1.bmp are provided.
// open these bmp in windows paint & change.(do not change size of bmp)
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-< Main >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
void main()
{
 int color,D=DETECT,E;
// registerfarbgidriver(EGAVGA_driver_far);
 initgraph(&D,&E,\"\");
 E=0;
 if(!ShowBMP(0,0,\"neeraj.bmp\")) E=1;
 getch();
 closegraph();
 if(E) printf(\"\\nError : Unable to open file.\");
 else printf(\"Sucess !\");
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    Related Post:
  1. Program to display different type of progress bar as displayed in windows system

  2. Use of the goto statement

  3. Example of preprocessor - 2

  4. Program to create header file for fork,join,shared memory,lock,free shared memory and free semaphore

  5. Program to display textbox works like the normal textbox found in Windows

  6. Example 1 to display array values and address of an array using pointers

  7. Program to writes numbers in a file and read and find odd or even numbers from it

  8. Program to convert binary to hexadecimal

  9. Program read a file name, serach it in C Drive, if multiple files are found, then display a list of these files with path on the screen...

  10. PROGRAM USNG WHILE LOOP FOR THE FIBONANSI SERIES AS SHOWN IN DESCRIPTION

  11. For a certain electrical circuit with an distance L and resistance R, the damped natural frequency is given by Frequency = sqrt((1/L*C)

  12. Program of histogram using loop splitting and locking the each bin with a different lock

  13. Function for inserting an item into a linked list

  14. PROGRAM TO READ AGE OF N PERSONS AND DISPLAY ONLY THOSE PERSONS WHOSE BETWEEN 50 AND 60

  15. Program to update stock price using structure pointer

  16. Formatted output of real numbers

  17. Program that accepts characters in lower case, stores them in an array and prints them in the upper-case and vice - versa

  18. Program to add two polynomials maintained as linked lists

  19. Program of telephone directory that provides append, find and display all records from a file

  20. Program that reads the encoded alphabetic text from a file and produces decoded file by replacing each character with the character that occurs five

 
 
Didn't find what you were looking for? Find more on Program to display a 16 color bitmap