Sunday, September 13, 2015
Graphic program to design calculator
In this program I used C graphics.
Not a big task, Only we need to know how to initialize Graphics then we can use inbuilt functions to design anything.
initgraph() is the function used to initialize graphics available in graphics.h library. It takes three parameter first one is reference to graphic driver, second one is reference to graphic mode and the last one is BGI library path.
Other functions I used are rectangle() to draw input box and buttons, line() for design, setcolor() to give color to shapes and outtextxy() to display text at specific x and y coordinates.
It looks like this :
Not a big task, Only we need to know how to initialize Graphics then we can use inbuilt functions to design anything.
initgraph() is the function used to initialize graphics available in graphics.h library. It takes three parameter first one is reference to graphic driver, second one is reference to graphic mode and the last one is BGI library path.
Other functions I used are rectangle() to draw input box and buttons, line() for design, setcolor() to give color to shapes and outtextxy() to display text at specific x and y coordinates.
It looks like this :
Program to read file in a program
File reading:
It requires understanding of two functions fopen and fgetc
fopen():
This function takes two parameters first one is file path and second one is file opening mode. there are six file modes in C language, those are r,w,a,r+,w+ and a+. Here we are using r for reading file.
fopen() returns a FILE pointer.
fgetc():
This function reads and returns one character at a time and moves pointer to the next character.
It requires understanding of two functions fopen and fgetc
fopen():
This function takes two parameters first one is file path and second one is file opening mode. there are six file modes in C language, those are r,w,a,r+,w+ and a+. Here we are using r for reading file.
fopen() returns a FILE pointer.
fgetc():
This function reads and returns one character at a time and moves pointer to the next character.
Program to print directory path
If we want to print path like C:\TC\BIN to our console, what we will do, we will put this string in printf like this
printf("C:\TC\BIN");
But the output will not be same as expected. Because there are some special symbols in the string those are making trouble for us. So we need to place extra backslash (\) to ignore those special symbols.
so the statement printf("C:\\TC\\BIN") will output as we want.
printf("C:\TC\BIN");
But the output will not be same as expected. Because there are some special symbols in the string those are making trouble for us. So we need to place extra backslash (\) to ignore those special symbols.
so the statement printf("C:\\TC\\BIN") will output as we want.
Powered by Blogger.