-1
我需要一些帮助或建议,我收到一个C编程任务... 任务是,alarm(sec)
需要调用一个信号SIGALRM
。 我必须在1秒内增加一个长整数,并在屏幕上打印出当时数量增加了多少倍。我怀疑它将不得不与alarm(1);
我有循环增加数字...位完全不知道如何在1秒后停止它,特别是与signal(SIGALRM,xxx)
我应该粘贴我的代码?信号和报警功能
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
int loop_function() {
int counter = 1;
long int n = 1;
while(n!=0) {
++counter;
n++;
printf("%d: %d\n",counter,n);
}
}
int main() {
loop_function();
}
确定 - :) 这里是我做了什么了...... 的#include 的#include 的#include INT loop_function(){ INT计数器= 1; long int n = 1; while(n!= 0){ ++ counter; n ++; 012fprintf(“%d:%d \ n”,counter,n); } } int main() { loop_function(); //我现在被卡住了...... } –
slavmir
为什么它看起来很奇怪? – slavmir
@slavmir用代码编辑你的答案,并用四个空格开始每行:) – Jacob