int vt_print_int(int num, char attr, int r, int c) { int i = 0; char temp[32]; char buf[32]; do { buf[i++] = '0' + num % 10; num /= 10; } while (num != 0); for (c = 0; i != 0; c++, --i) { temp[c] = buf[i-1]; } vt_print_string(temp, attr, r, c); }
int vt_draw_frame(int width, int height, char attr, int r, int c) { char border = '#'; //Char to use for the frame char *line = malloc(width*sizeof(char)); //Allocate space equivalent to the width of the frame unsigned int i; for(i=0;i<width;i++){ line[i] = border; //Fill in the line with the border char defined previously } int result; for(i=0;i<height;i++){ if(i==0 || i == height-1) //If it's the first and last line draw the frame horizontally result = vt_print_string(line, attr, r+i, c); else{ //Else only draw the first and last char result = vt_print_char(border, attr, r+i, c); result = vt_print_char(border, attr, r+i, c+width-1); } } free(line); return result; }
int vt_print_int(int num, char attr, int r, int c) { if(r >= scr_lines || c >= scr_width || r < 0 || c < 0 ) return 1; int aux = num, count = 0; char *vptr; vptr = video_mem; vptr = vptr + 2 * r * scr_width + 2 * c; while(aux % 10 != 0){ count++; aux = aux /10; } if(num < 0) count = count+1; char int_str[count]; sprintf(int_str, "%d", num); vt_print_string(int_str, attr, r, c); return 0; }
int vt_print_int(int num, char attr, int r, int c) { char * str; unsigned int size = 0; if(num<0){ //If it is a negative number, insert a '-' in the beginning size++; num *= -1; str[0] = '-'; } int n = num; do{ // Get the number of digits of the number size++; n = n/10; }while(n); /* ALTERNATE METHDO str = malloc(size*sizeof(char)); sprintf(str, "%d", num); */ n = num; str = malloc(size*sizeof(char)); int i; for(i = size-1; i >= 0; i--){ // Move back, inserting digits as u go str[i] = (n%10)+0x30; //Insert the digit converted to ASCII n = n/10; } str[size] = '\0'; int res = vt_print_string(str,attr,r,c); free(str); return res; }
int vt_print_int(int num, char attr, int r, int c) { char str[12] = { 0 }; sprintf(str, "%d", num); return vt_print_string(str, attr, r, c); }