我想知道是否有任何方法可以将一行内容从控制台窗口复制到字符串中。
例如
#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/