我正在尝试使用此代码读取0到255(unsigned char)之间的值.
#include<stdio.h>
int main(void)
{
unsigned char value;
/* To read the numbers between 0 to 255 */
printf("Please enter a number between 0 and 255 \n");
scanf("%u",&value);
printf("The value is %u \n",value);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我按预期得到了以下编译器警告.
warning: format ‘%u’ expects type ‘unsigned int *’, but argument 2 has type ‘unsigned char *’
这是我对该计划的输出.
Please enter a number between 0 and 255 45 The value is 45 Segmentation fault
运行此代码时,我确实遇到了分段错误.
unsigned char使用读取值的最佳方法是什么scanf?
我想用逗号替换字符串中的空格/空格.
STR1=This is a string
Run Code Online (Sandbox Code Playgroud)
至
STR1=This,is,a,string
Run Code Online (Sandbox Code Playgroud) 我想知道有没有办法将我的shell变量导出到系统中的所有会话(不仅是当前会话).我不打算在.bashrc文件中设置它,因为shell变量是一个动态的变量,它不时变化.
我可以将指针分配给整数变量吗?如下所示。
int *pointer;
int array1[25];
int addressOfArray;
pointer = &array1[0];
addressOfArray = pointer;
Run Code Online (Sandbox Code Playgroud)
有可能这样做吗?
我有以下脚本成功运行。但是,如果我尝试使用通配符复制多个文件,则会引发错误,说“没有这样的文件或目录”。
此代码有效:
#!/usr/bin/expect -f
spawn scp file1.txt root@192.168.1.156:/temp1/.
expect "password:"
send "iamroot\r"
expect "*\r"
expect "\r"
Run Code Online (Sandbox Code Playgroud)
以下不起作用:
#!/usr/bin/expect -f
spawn scp * root@192.168.1.156:/temp/. #fails here
….
Run Code Online (Sandbox Code Playgroud) 我有以下数组,我打算将其用作循环缓冲区。
int array1[20];
Run Code Online (Sandbox Code Playgroud)
该数组由一个线程写入并由另一个线程读取。在阅读时,我需要读取写入该数组的最后 3 个值。
写作工作正常。我用
writeIndex = (writeIndex + 1) %20;
Run Code Online (Sandbox Code Playgroud)
来写。这很好地将数组索引 0 滚动到 19。
为了阅读,我正在使用
readIndex = (readIndex -1)%20;
Run Code Online (Sandbox Code Playgroud)
但它不起作用当我尝试从索引 0 到 19 时。
我在Makefile(GNU)中使用sub-make.但是,只要sub-make失败,主make就会继续成功运行.每当我的子make失败时,我希望我的主Makefile失败.我怎么做?
all:
pushd ${STA_DIR};make clean;make ARGS=${A1},${A2};popd
Run Code Online (Sandbox Code Playgroud)
每当STA_DIR中的make失败时,主make就不会停止.我想主要制作停止.