c语言输入数据按回车不换行继续输入数据怎么做到?
5条回答 默认 最新
CSDN专家-link 2021-12-30 11:40关注如下代码可实现只回车不换行
#include <Windows.h> #include <conio.h> void gotoxy(int x, int y) { COORD pos = {x,y}; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄 SetConsoleCursorPosition(hOut, pos);//两个参数分别是指定哪个窗体,具体位置 } int main() { printf("hello,I love you"); char ch = getch(); if(ch == '\n') gotoxy(0,0); char s[100]; gets(s); puts(s); return 0; }解决 无用评论 打赏 举报 编辑记录