cwindowsstringconsoleconio

How to copy content of a line into string by giving line's coordinates


I want to know if there is any way to copy content of a line from console window into string. For example

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
 int main()
 {
  char a[10];int b;  int x1,y1,x2,y2,x3,y3;

  x1=wherex(); y1=wherey();
  printf("Enter your name : ");
  scanf("%s",&a);
  x2=wherex(); y3=wherey();
  printf("Enter your age : ");
  scanf("%d",&b);
  x3=wherex(); y3=wherey();
  printf("Enter your gender : ");
  scanf("%d",&a);

  char copyline1[80];char copyline2[80];char copyline3[80];
  gotoxy(x1,y1);
  copyline1[]= ??? // What to do to Copy content of line 1 into copyline1[]
  gotoxy(x2,y2);
  copyline2[]= ??? // What to do to Copy content of line 2 into copyline2[]
  gotoxy(x3,y3);
  copyline3[]= ??? // What to do to Copy content of line 3 into copyline3[]

  printf(" First line is\n");
  puts(copyline1);  // This will print Enter your name : abc
  printf(" Second line is\n");
  puts(copyline2);  // This will print content of line 2 of console window
  printf(" Third line is \n");
  puts(copyline3);

  return 0;
 }

I want to copy content of line into string by giving line's coordinates , if possible !


Solution

  •     char buf[70];
        COORD coord = {x-coordinate,y-coordinate};
        DWORD num_read;
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        ReadConsoleOutputCharacter(hConsole,(LPTSTR) buf,(DWORD) 70,coord,(LPDWORD) &num_read);
        buf[69]='\0';
    

    Content of the line is now copied into char buf.