该程序将其输入复制到其输出,用backspace()替换TAB(\t).但是在我的代码中,当我输入退格键时,我无法读取输入字符,因为选项卡不起作用.\t\b\b
在Linux中使用GCC进行编译:
#include<stdio.h>
int main(void)
{
int c=0;
while((c=getchar())!=EOF){
if(c=='\t'){
printf("\\t");
if(c=='\b')
printf("\\b");
}
else
putchar(c);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
假设我输入vinay(tab)hunachyal
Output:vinay\thunachyal
Run Code Online (Sandbox Code Playgroud)
如果我输入vinay(和1个退格)
Output:vina
Run Code Online (Sandbox Code Playgroud)
所以我的疑问是为什么vina\b在这种情况下不打印?
是否可以检测\b和打印\b?如果不是什么原因
Note: 我需要在运行时输入退格键不提供单独的文件\ b
我最近遇到的问题是如何访问一个在file1.c中声明为static的变量到另一个file2.c?
是否可以访问静态变量?
我对C中静态关键字的理解是,
static是"内部链接",因此只能从一个编译单元访问它们 - 它们被定义的单元.使用内部链接声明的对象是单个模块的私有对象.
正如我的一位朋友建议我解决方案.
在 file1.c
#include <stdio.h>
int main()
{
int b=foo();
printf("%d",b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在 file2.c
static int a=25;
int foo()
{
return a;
}
Run Code Online (Sandbox Code Playgroud)
汇编 gcc file1.c file2.c -o file
如果我在上面,我可以访问变量.
所以我的问题是:
上述程序是否违反静态变量规则?
如果没有,为什么会这样,除了包括file(#include <…>)之外,还有其他方法可以访问静态变量.
如果我对静态变量概念有误,并且有更好的解决方案可用于访问静态变量,请纠正我?
我试图在qemu环境中使用GDB逐步了解内核启动顺序.
以下是我的设置:
在一个终端即时运行
~/Qemu_arm/bin/qemu-system-arm -M vexpress-a9 -dtb ./arch/arm/boot/dts/vexpress-v2p-ca9.dtb -kernel ./arch/arm/boot/zImage -append "root=/dev/mmcblk0 console=ttyAMA0" -sd ../Images/RootFS.ext3 -serial stdio -s -S
Run Code Online (Sandbox Code Playgroud)
在其他终端
arm-none-linux-gnueabi-gdb vmlinux
Reading symbols from vmlinux...done.
(gdb) target remote :1234
Remote debugging using :1234
0x60000000 in ?? ()
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在/ arch/arm/boot/compressed/*文件中设置代码的断点.
例如,我试图为misc.c中定义的decompress_kernel设置断点.
情况1:
(gdb) b decompress_kernel
Function "decompress_kernel" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (decompress_kernel) pending.
(gdb) c
Continuing.
Run Code Online (Sandbox Code Playgroud)
上面的一个是无法启动qemu启动的功能.
案例2:
(gdb) b *0x80008000
Breakpoint 1 at 0x80008000: file arch/arm/kernel/head.S, line …Run Code Online (Sandbox Code Playgroud) 在Linux源代码中
tolower和topupper的实现如下实现
static inline unsigned char __tolower(unsigned char c)
{
if (isupper(c))
c -= 'A'-'a';
return c;
}
static inline unsigned char __toupper(unsigned char c)
{
if (islower(c))
c -= 'a'-'A';
return c;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用XOR(^)按位运算,如下所示.
如果我使用xor操作,是否有任何潜在的Bug?
c -= 'A'-'a'; ----> c = c ^ 0x20 ; //using xor to convert to lower case to upper case and vice versa
Run Code Online (Sandbox Code Playgroud)