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 find minimum and maximum from an array using structure

  2. Program to repeat every Key Press event three times

  3. BISECTION METHOD FOR PARTICULAR

  4. Program to inter change to number in each other

  5. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  6. Program using do-while loop that will calculate the sum of every third integer beginning with i=2 sum = 2+5+8+11+.)for values less than 100

  7. Queue with array

  8. NEWTONS FORWARD DIFFERENCE INTERPOLATION

  9. To show the use of stack in function calls

  10. Example to display multi dimentional array values using functions

  11. Doubly circular link list or Circular doubly link list

  12. Program to compare one string s2 to another string s1. Print the difference of first unmatched characters (Without Using strcmp function)

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

  14. Program to create a singly linked list of numbers using threads

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

  16. Program that takes characters from user in an array and prints them with their ASCII values.(Do not use atoi function)

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

  18. Program to count number of employee in the company using structures / file

  19. Program that illustrates the use of pointers

  20. Program to copy the contents of one array to another using shared memory

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