小编Gra*_*orð的帖子

获取C中当前按下的键?

我需要能够在不完全停止程序的情况下按下当前角色.理想情况下,我希望程序继续运行,在while循环的每次迭代后检查密钥.getch()由于这个原因是有问题的.我想在按下'q'键时突破while循环,但是while循环继续运行直到那时.我使用Linux和gcc作为我的编译器.

c linux

3
推荐指数
1
解决办法
221
查看次数

为什么C打印输出较晚?

我目前正在我的Raspberry Pi计算机上运行一段C代码.它是一个随机数发生器,从连接到GPIO数字输入18的Geiger计数器读取.它产生随机位(见代码)并以8组为单位打印位.此外,每隔30秒,它打印出当前观察到的辐射水平.代码似乎工作正常,除非辐射源被带走.随机数的生成速度较慢,但​​它似乎也会减慢其余任务的速度.在程序开头打印的消息在生成一个随机数之前不会显示.发生这种情况时,不显示任何数字,但添加了一个没有数字的换行符.即使在程序运行时,辐射水平似乎每30秒打印一次,但也会在下一个随机数上打印.为什么C以错误的顺序执行代码?

#include <wiringPi.h>//library for I/O
#include <stdlib.h>
int main(int argc, char *argv[])
{
    int lastRead;//if this is first time observing current pulse
    int pulseCount = 0;//number of total pulses from Geiger counter
    long timing[4] = {0,0,0,0};//values to compare to produce one bit
    int bits[8] = {0,0,0,0,0,0,0,0};//the newest number
    int bitCount = 0;//counts how many random bits have been made
    int i = 0;
    float startTime = 0;//start of the clock
    float currentSec = 0;
    float currentMin = 0;
    float …
Run Code Online (Sandbox Code Playgroud)

c linux raspberry-pi

2
推荐指数
1
解决办法
87
查看次数

标签 统计

c ×2

linux ×2

raspberry-pi ×1