c - 如何通过给出行的坐标将行的内容复制到字符串中

标签 c windows string console conio

我想知道是否有任何方法可以将控制台窗口中的一行内容复制到字符串中。 例如

#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;
 }

如果可能的话,我想通过给出线的坐标将线的内容复制到字符串中!

最佳答案

    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';

该行的内容现在被复制到 char buf 中。

关于c - 如何通过给出行的坐标将行的内容复制到字符串中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30817389/

相关文章:

c - 将字符串文字的地址分配给指针

c - 错误: 'for' loop declarations only in c99 mode

javascript - 使用 JavaScript 从 HTML 字符串中提取文本

c# - 正则表达式提取括号之间还包含其他括号的字符串

c - 内存泄漏。无法释放 malloc'ed char*

c - 即使添加了 #include <stdio.h> 也隐式声明了 popen

javascript - 为什么 Node mkdirSync() 会抛出异常?

windows - 使用 `^` 转义 Windows 批处理文件中的行尾字符在某些行上不起作用?

windows - 从指纹传感器保存的图像似乎已损坏

python - 从字符串中剥离注释行