3 Replies - 679 Views - Last Post: 22 September 2009 - 10:27 PM Rate Topic: -----

#1 zhao0726  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-September 09

how to get a number from screen

Posted 22 September 2009 - 03:53 AM

how to get a number from screen

i wanna get a number from screen

use _conio_gettext(int,int,int,int,*char)


#include <stdio.h>
#include <conio.h>

int main()
{
 printf("12345678901234567890\n");
 char *buffer[20];
 char buf[20];
 buffer[20]=&buf[20];
 _conio_gettext(1,1,1,1,buffer);
 printf("%s",buf);
 return 0;
}



i can get a right value

who can help me

Is This A Good Question/Topic? 0
  • +

Replies To: how to get a number from screen

#2 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: how to get a number from screen

Posted 22 September 2009 - 07:42 AM

Get a number from screen? Do you mean from the buffer? What number do you want to get? What does your function _conio_gettext() do?
Assuming that you want to fill the array with the numbers you have printed to the screen, you can do it this way.

int main(){

printf("12345678901234567890\n");
char *buffer[20];
char buf[20]= {'1','2','3','4','5','6','7','8'};//fill it. I only used 8 places, to test it
buffer[20]=&buf[20];
//_conio_gettext(1,1,1,1,buffer); //not sure what this does so I commented it out

printf("%s",buf);


If this is not the answer you are looking for, perhaps you can give more details explaining the problem. :)
Was This Post Helpful? 0
  • +
  • -

#3 zhao0726  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-September 09

Re: how to get a number from screen

Posted 22 September 2009 - 08:13 PM

View PostOliveOyl3471, on 22 Sep, 2009 - 06:42 AM, said:

Get a number from screen? Do you mean from the buffer? What number do you want to get? What does your function _conio_gettext() do?
Assuming that you want to fill the array with the numbers you have printed to the screen, you can do it this way.

int main(){

printf("12345678901234567890\n");
char *buffer[20];
char buf[20]= {'1','2','3','4','5','6','7','8'};//fill it. I only used 8 places, to test it
buffer[20]=&buf[20];
//_conio_gettext(1,1,1,1,buffer); //not sure what this does so I commented it out

printf("%s",buf);


If this is not the answer you are looking for, perhaps you can give more details explaining the problem. :)



i alread put the string on the screen, and i wanna scan the string and put it on the screen again

This post has been edited by zhao0726: 22 September 2009 - 08:15 PM

Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: how to get a number from screen

Posted 22 September 2009 - 10:27 PM

...Odd thing to do... actually it is not that easy. The good old days of DOS programming that was easy but now its a dive into the windows API...

If we look here we will find a list of windows console functions... we want to find something that can read something from the screen (console buffer). I would say that ReadConsoleOutputCharacter looks like it just might do the trick...

#include <windows.h>
#include <stdio.h>
#include <stdarg.h> // for printfAt function...
int ReadCharsFrom(int x, int y, int len, char *buffer);

//from snippet: http://www.dreamincode.net/code/snippet1504.htm
int printfAt(int x, int y, const char *format, ...);

//from snippet: http://www.dreamincode.net/code/snippet921.htm
void ClearConsole();


int main() {
	char aBuffer[100];
	ClearConsole();
	printfAt(20, 5, "Pi is %f", 3.14159265);
	ReadCharsFrom(26,5,8,aBuffer);
	printfAt(20, 7, "Value read was: %s\n", aBuffer);
	return 0;
}

int ReadCharsFrom(int x, int y, int len, char *buffer) {
	HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD charsRead = 0;
	COORD pos = {x, y};
	ReadConsoleOutputCharacter(hStdOut, buffer, len, pos, &charsRead);
	buffer[charsRead]=0;
	return charsRead;
}

int printfAt(int x, int y, const char *format, ...) {
	DWORD count; //WriteConsole will tell us how many characters is actually prints
	COORD coord = {x, y}; //This is will be used to set the cursor location
	HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); //get the handle to the current console
	char buffer[256]; //our buffer, note that its maximum size is 255 (plus a 0x00 at the end).
	int len; //used to tell how much of the buffer was used.
	va_list args; //the argument list
	va_start (args, format); //set up the argument list to be passed to vsprintf()
	//This is how we can pass along our argument list using
	// the vsprintf function. 
	len = vsprintf (buffer,format, args);
	//Windows API function to set the position of the cursor.
	SetConsoleCursorPosition(hStdOut, coord); 
	//Windows API function to print to the console
	WriteConsole(hStdOut, buffer, len, &count, NULL);
	va_end (args);
	return len; //number of characters that we needed
}

void ClearConsole()
{
	 //Get the handle to the current output buffer...
	 HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	 //This is used to reset the carat/cursor to the top left.
	 COORD coord = {0, 0};
	 //A return value... indicating how many chars were written
	 //   not used but we need to capture this since it will be
	 //   written anyway (passing NULL causes an access violation).
	 DWORD count;
	 //This is a structure containing all of the console info
	 // it is used here to find the size of the console.
	 CONSOLE_SCREEN_BUFFER_INFO csbi;
	 //Here we will set the current color
	 if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
	 {
		  //This fills the buffer with a given character (in this case 32=space).
		  FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
		  FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
		  //This will set our cursor position for the next print statement.
		  SetConsoleCursorPosition(hStdOut, coord);
	 }
	 return;
}


well its up to you to convert the string back into a number or whatever.. that will read chars from the screen in windows. (not linux)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1