Tag: 输入

C – 键入字符时从stdin读取

如何在输入字符时填充80个字符的缓冲区,或者直到按下回车键或缓冲区已满,以先发生者为准。 我已经研究了很多不同的方法,但必须按下输入然后输入字符*在80处被切断。 谢谢。

在C中的文本文件中读取,将行分成多个变量

我目前正在开发一个模拟各种CPU调度方法的程序。 目前我有程序要求输入: printf(“Enter type of CPU scheduling algorithm (SJF, RR, PR_noPREMP, PR_withPREMP): “); scanf(“%s”, typeOf); printf(“Enter number of processes: “); scanf(“%d”, &numPro); struct processStruct structs[numPro]; int burstTimes[numPro]; for (i = 0; i < numPro; i++) { printf("Enter process number: "); scanf("%d", &structs[i].pNum); printf("Enter arrival time: "); scanf("%d", &structs[i].arTime); printf("Enter CPU burst time: "); scanf("%d", &structs[i].cpuBur); […]

C:gets()跳过第一个输入

#include #include #include #include typedef struct record { char name[20]; char surname[20]; char telephone[20]; }Record; typedef struct node { Record data; struct node *next; }Node; Node *head = NULL; void addRecord(Record s) { Node *newNode; Node *n; newNode = (Node*)malloc(sizeof(Node)); newNode->data = s; newNode->next = NULL; if (head == NULL) { // The linked list […]

程序正在跳过fgets而不允许输入

基本上如标题所示..当我的程序从控制台运行时,它会询问你是否要加密或解密..当我输入e或E时,它会创建一个新的空行(直到我输入一些那种文字),然后一次显示“输入文字”和“输入密钥”行。 因此,在控制台中它看起来像: 你想(E)ncrypt还是(D)ecrypt? Ë asdf jkl; <—-随机用户输入以使程序继续.. 输入要加密的文本:输入用于加密的密钥:(用户输入) 然后程序退出.. //message to be encrypted char text[250]; //word to use as the key char key[50]; //stores the encrypted word char encrypted[250]; char answer; printf(“Would you like to (E)ncrypt or (D)ecrypt? “); scanf(” %c”, &answer); if(answer == ‘e’ || answer == ‘E’) { printf(“Enter the text you want […]

select()没有响应写入/ dev / input / mice

我正在编写一个程序,通过键盘和鼠标设备文件上的select()进行监视。 它等待这些文件上的任何写操作(这应该在键击或鼠标移动时发生),并且只要有写操作,就会执行一些作业。 但它不起作用。 我的代码如下。 #include #include #include #include #include #include #include #include #include void main() { int mouse_fd,kbd_fd,fd_max; struct input_event ev; fd_set rfs,wfs; if((mouse_fd=open(“/dev/input/event3”,O_WRONLY))==-1) { printf(“opening mouse device file has failed \n”); } else { printf(“opening mouse device file has been successfull \n”); } if((kbd_fd=open(“/dev/input/event2”,O_WRONLY))==-1) { printf(“opening keyboard device file has failed \n”); } else […]

如何在C中正确输入字符串

我目前正在学习C,所以我想创建一个程序,要求用户输入一个字符串并输出输入的字符数,代码编译得很好,当我只输入1个字符就可以了,但是当我输入2个或更多字符,无论我输入的字符数是多少,它总会说只有一个字符然后崩溃。 这是我的代码,我无法弄清楚出了什么问题。 int main(void) { int siz; char i[] = “”; printf(“Enter a string.\n”); scanf(“%s”, i); siz = sizeof(i)/sizeof(char); printf(“%d”, siz); getch(); return 0; } 我目前正在学习编程,所以如果有办法使用相同的scanf()函数,我会很感激,因为我还没有学会如何使用任何其他函数,可能无法理解它是如何工作的。

使用fscanf从给定行读取

我想读一个最多10行的txt文件。 该文件的格式如下所示: 1 1 8 2 2 3 3 1 15 4 2 7 我正在尝试编写一个只从传递给它的int提供的行读取的函数。 我想过使用for循环遍历这些行而不扫描任何东西,但我无法弄清楚如何实现它。 到目前为止我的function看起来像这样,for循环还没有正确实现。 void process(int lineNum, char *fullName) { int ii, num1, num2, num3; FILE* f; f = fopen(fullName, “r”); if(f==NULL) { printf(“Error: could not open %S”, fullName); } else { for (ii=0 (ii = 0; ii < (lineNum-1); ii++) { […]

如何在c中正确printf整数和字符串?

我有以下代码: char *s1, *s2; char str[10]; printf(“type a string: “); scanf(“%s”, str); s1 = &str[0]; s2 = &str[2]; printf(“%s\n”, s1); printf(“%s\n”, s2); 当我运行代码时,输​​入输入“A 1”如下: type a string: A 1 我得到以下结果: A < 我正在尝试将第一个字符作为字符串读取,将第三个字符作为整数读取,然后在屏幕上打印出来。 第一个角色总是有效,但屏幕只会在那之后显示随机的东西….我该如何解决? 谢谢

跨平台键盘/鼠标输入推荐

有没有人对一个好的跨平台输入库有任何建议? 我想得到: * at least keyboard and mouse input * on at least the big three operating systems * Small/fast * C or C++ * permissive licensing gpl2/mit/free/etc. 到目前为止,我见过: * OIS (used in Ogre) http://sourceforge.net/projects/wgois/ * SDL (used everywhere it seems, might be a clue) http://www.libsdl.org/index.php * Allegro http://www.talula.demon.co.uk/allegro/readme.html 有没有人使用过这些,或者知道其他可能有用的东西? 谢谢

如何减少NCurses C应用程序中的输入延迟

当我运行我的应用程序时,我得到了大量的输入延迟。 更多细节:当我按下“w”,“a”,“s”,“d”(我指定的输入键)时,对象会移动,但是在释放按键后它会继续移动很长一段时间。 源代码如下,但是代码的一小部分已经被删除以缩短问题,但是如果下面的源代码没有编译,我将所有代码都放在github上。 https://github.com/TreeStain/DodgeLinuxGame.git谢谢您的时间。 -Tristan dodge.c: #define ASPECT_RATIO_X 2 #define ASPECT_RATIO_Y 1 #define FRAMES_PER_SECOND 60 #include #include “object.h” #include “render.h” int main() { initscr(); cbreak(); noecho(); nodelay(stdscr, 1); object objs[1]; object colObj; colObj.x = 10; colObj.y = 6; colObj.w = 2; colObj.h = 2; colObj.sprite = ‘*’; colObj.ySpeed = 1; colObj.xSpeed = 1; objs[0] = […]