Tuesday, October 23, 2018

C Language Memory Allocation Functions for B.C.A., B.Sc.(IT) and P.G.D.C.A. Students


--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOT- IT)
Contact No : 7600044051
Email : rupareleducation@gmail.com


Dynamic memory allocation in C

The concept of dynamic memory allocation in c language enables the C programmer to allocate memory at runtime. Dynamic memory allocation in c language is possible by 4 functions of stdlib.h header file.
  1. malloc()
  2. calloc()
  3. realloc()
  4. free()

  • malloc() : allocates single block of requested memory.
  • calloc()  : allocates multiple block of requested memory.
  • realloc() : reallocates the memory occupied by malloc() or calloc() functions.
  • free()  : frees the dynamically allocated memory

malloc() :

  • The malloc() function allocates single block of requested memory.
  • It doesn't initialize memory at execution time, so it has garbage value initially.
  • It returns NULL if memory is not sufficient.
  • The syntax of malloc() function is given below:

ptr=(cast-type*)malloc(byte-size) 


calloc() :

  • The calloc() function allocates multiple block of requested memory.
  • It initially initialize all bytes to zero.
  • It returns NULL if memory is not sufficient.
  • The syntax of calloc() function is given below:

ptr=(cast-type*)calloc(number, byte-size)


realloc() :

  • If memory is not sufficient for malloc() or calloc(), you can reallocate the memory by realloc() function. In short, it changes the memory size.
  • Let's see the syntax of realloc() function.

ptr=realloc(ptr, new-size) 


free() :

  • The memory occupied by malloc() or calloc() functions must be released by calling free() function. Otherwise, it will consume memory until program exit.
  • Let's see the syntax of free() function.


free(ptr)  


:: Best Of Luck ::

Please comment and share it..... Thank You.


Monday, October 22, 2018

Graphics Library Function for B.C.A , B.Sc.(IT) and P.G.D.C.A. Students


--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD - IT)
Mobile No : 7600044051
E-Mail : rupareleducation@gmail.com


GRAPHICS.H Header file

Graphics header file will provide many functions to create your own graphics and you can design your own games also using graphics.h header file. Some of the functions have described below.


Function
Declaration
Description
initgraph
void  initgraph(int  *graphdriver, int  *graphmode, char  *pathtodriver);
Initializes the graphics system. To start the graphics system you must first call initgraph.
line
void  line(int x1, int y1, int x2, int y2);
Line draws a line between two specified points.
circle
void  circle(int x, int y, int radius);
Circle draws a circle in current drawing color.
ellipse
void  ellipse(int x,int y, int stangle, int endangle, int xradius, int yradius);
Draws an elliptical arc in the current drawing color.
getx
int  getx(void);
Returns the current position’s x coordinate.
putx
int  getx(void);
Returns the current position’s x coordinate.
setcolor
void  setcolor(int color);
Setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor.
setbkcolor
void  setbkcolor(int color);
Setbkcolor sets the current background to the specified color.
arc
void  arc(int x, int y, int endangle, int radius);
arc draws a circular arc in the current drawing color.
pieslice
void  pieslice(int x, int y, int stangle, int endangle, int radius);
Pieslice draws a pie slice in the current drawing color, then fills it using the current fill pattern and fill color.
bar
void  bar(int left, int top, int right, int bottom);
Bar draws a filled in, rectangular, two-dimensional bar. The bar is filled using the current fill pattern and fill color.
bar3d
void  bar3d(int left, int top, int right, int bottom, int depth, int topflag);
Bar3d draws a three- dimensional rectangular bar, and then fills it using the current fill pattern and fill color. The three dimensional outline of the bar is drawn in the current line style and color. Topflag governs whether a three dimensional top is put on the bar. Outline bar can be drawn by assigning depth=0. If topflag is nonzero, a top is put on the bar. If topflag is zero, no top is put on the bar.
cleardevice
void  cleardevice(void);
Clear device erases the entire graphics screen and moves the current position to home (0,0).
closegraph
void  closegraph(void);
Shuts down the graphics system. Close graph deallocates all memory allocated by the graphics system.
drawpoly
void  drawpoly(int numpoints, int  *polypoints);
Drawpoly draws outline of a polygon using the current line style and color.
fillpoly
void  fillpoly(int numpoints, int  *polypoints);
Fillpoly draws the outline of a polygon using the current line style and color, then fills the polygon using current fill pattern and fill color.
fillellipse
void  fillellipse(int x, int y, int xradius, int yradius);
It draws an ellipse, and then fills the ellipse with the current fill color and pattern.
sector
void  sector(int x, int y, int stangle, int endangle, int xradius, int yradius);
Draws and fills an elliptical pie slice.
getimage
void  getimage(int left, int top, int right, int bottom, void *bitmap);
Getimage saves a bit image of the specified region into memory.
putimage
void  putimage(int left, int top, void  *bitmap, int op);
putimage puts the bit image previously saved with getimage back onto the screen, with the upper left corner of the image placed at (left, top);
getmaxcolor
int  getmaxcolor(void);
Getmaxcolor returns the highest valid color value that can be passed to the setcolor for current graphics driver and mode.
getmaxx
int  getmaxx(void);
it returns the maximum screen related x value for the current graphics driver and mode.
getmaxy
int  getmaxy(void);
it returns the maximum screen related y value for the current graphics driver and mode.
gety
int  gety(void);
returns the current position’s y coordinate
graphresult
int  graphresult(void);
Returns an error code for the last unsuccessful graphics operation.
lineto
void  lineto(int x, int y);
Lineto draws a line from the current position to (x,y).
outtext
void  outtext(char  *textstring);
Outputs textstring at the current position.
outtextxy
void  outtextxy( intx, int y, char  *textstring);
Displays textstring in the viewport at the position (x,y).
rectangle
void  rectangle(int left, int top, int right, int bottom);
Draws a rectangle in the current line style, thickness, and drawing color.
setfillpattern
void  setfillpattern(char  *upattern, int color);
Setfillpattern sets the current fill pattern to a user-defined 8x8 pattern.
setfillstyle
void  setfillstyle(int pattern, int color);
Sets the fill pattern and color.
setlinestyle
void  setlinestyle(int line style, unsigned upattern, int thickness);
sets the style for all lines drawn by line, lineto, rectangle, drawpoly, etc.
settextjustify
void  settextjustify(int horiz, int vert);
Settext justification for graphics mode.
settextstyle
void  settextstyle ( int font, int direction, int charsize);
Settextstyle sets the text font, the direction in which text is displayed, and the size of the characters.