1

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

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

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

4

1 回答 1

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 中。

于 2015-10-25T10:26:35.123 回答