SOME BASIC KNOWLEDGE:
KEYWORD | FUNCTION | EXAMPLE INPUT | EXAMPLE OUTPUT |
---|---|---|---|
printf | prints the string written within the quotation marks | printf("Hello"); | Hello ,Use cout in C++ |
#include<stdio.h> | calls the standard input/output function | #include <stdio.h> | Use #include <iostream.h> in C++ |
int main() | creates main function to run the program | int main() | Use return var; to report to environment(DOS..) |
scanf | inputs a variable or string | scanf("%d", &variableName); | inputs a list of variables |
%d %lf | %d = an integer; %lf = a decimal number | printf("%d", variableName); | prints the variable amount |
An example using printf() with different formats to print out number in HEX, DEC, OCT
#define UPTO 17 int main(void) { int i ; printf("%10s%10s%10s%10s%10s%10s\n","Dec","Oct","Hex","Dec","Oct","Hex"); printf("%60s\n","-----------------------------------------------------"); for (i=0;i<UPTO;i++){ printf("%10d%10o%10x%10d%10o%10x\n",i,i,i,i+UPTO,i+UPTO,i+UPTO); } return 0; }
Convert a decimal to binary : 35 divided by 2 remains 1 left 17 divided by 2 remains 1 left 8 divided by 2 remains 0 left 4 divided by 2 remains 0 left 2 divided by 2 remains 0 left 1 divided by 2 remains 1 Collect the binary bottom up side : 100011
FAQ:
Any questions or answers please help meSOURCE CODE ( OR USEFULL FUNCTIONS):
One way to accomplish this is:
union REGS inout;
#ifdef __WATCOMC__
inout.w.ax = 0x0013; //Mode 13h or 320x200,256 colors
int386(0x10,&inout,&inout);
#else
inout.x.ax = 0x0013;
int86(0x10,&inout,&inout);
#endif
After that you can access directly to screen by:
unsigned far char *screen = (unsigned far char *)0x0A000000
You can either use the directives(prog < > data.dat) or open the file :
int main(void) { char temp; while ((temp=getchar())!=EOF){ do something.. } return 0; } or open file: #include#include int main(int agrc,char *agrv[]) { FILE *fp; char filename[] ,temp; if (argc>1){ //There are parameters filename = argv[x];//x is where you type filename fp=fopen(filename,"rb")//"r" for readonly "w" for write.. while ((temp=fgetc(fp))!=EOF){ do something... } else Printf("Usage:prog param1\n"); } return 0;//You can put return 1;for error in the print Usage }
void DecToBin(int number,char bin[],char f_char) { int cnt=IBSIZE,remain,num=number; do{ remain=num%2; if (remain==1) bin[cnt]='1'; else bin[cnt]='0'; num/=2; cnt--; }while (num>0); while (cnt>=0){ bin[cnt]=f_char; cnt--; } bin[BITS-1]='\0'; }