小编dev*_*per的帖子

如何在bash字符串中添加新行?

\nshell字符串中不考虑新行

root@toto:~# str="aaa\nbbbb"
root@toto:~# echo $str
aaa\nbbbb
Run Code Online (Sandbox Code Playgroud)

预期结果:

root@toto:~# echo $str
aaa
bbbb
Run Code Online (Sandbox Code Playgroud)

如何在字符串中添加新行?

linux bash shell sh ash

32
推荐指数
1
解决办法
7万
查看次数

什么"内联__attribute __((always_inline))"在函数中意味着什么?

我找到了以下函数定义:

static inline __attribute__((always_inline)) int fn(const char *s)
{
  return (!s || (*s == '\0'));
}
Run Code Online (Sandbox Code Playgroud)

而且我想知道它的含义inline __attribute__((always_inline))

c gcc

12
推荐指数
2
解决办法
2万
查看次数

在C源代码中包含项目的SVN修订版

如何在C源代码或Makefile中包含我的项目的SVN修订版(不是文件修订版)?

c svn revision project

9
推荐指数
1
解决办法
3383
查看次数

在C程序中调用的Linux重启函数会导致程序在磁盘上创建文件丢失

我已经开发了一个C程序(Linux),这个程序创建一个新文件并写入,然后重新启动PC.

重启后,我丢失了程序创建的文件.当我停用重启功能时,我的程序创建的文件仍然存在.

在Linux上可以看到这种行为: - VirtualBox上的OpenWrt(Backfire 10.03)(文件系统ext2) - Linux(Ubuntu)(文件系统ext4)

您是否已解释此行为以及如何解决此问题?

#include <stdio.h>
#include <sys/reboot.h>

int main ()
{
    FILE    *pFile;
    char    mybuffer[80];

    pFile = fopen ("/home/user/Desktop/example.txt","w");
    if (pFile == NULL) perror ("Error opening file");
    else
    {
        fputs ("test",pFile);
        fclose (pFile);
    }
    rename("/home/user/Desktop/example.txt","/home/user/Desktop/example123.txt");
    reboot(RB_AUTOBOOT);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c linux reboot

7
推荐指数
2
解决办法
8991
查看次数

如何使用apple bonjour for iOS阅读TXT记录

我试图在didFindService函数中获取TXTrecords,但我发现该值为null.

你有什么想法解决我的问题吗?

- (void)netServiceBrowser:(NSNetServiceBrowser*)netServiceBrowser didFindService:(NSNetService*)service moreComing:(BOOL)moreComing {
    [self.services addObject:service];

    NSDictionary* dict = [[NSNetService dictionaryFromTXTRecordData:[service TXTRecordData]] retain];
    MyTreeNode *node = [[MyTreeNode alloc] initWithValue:[service name]];
    NSString* info = [self copyStringFromTXTDict:dict which:@"info"];
    if([info isEqualToString:@"child"]) { // info == null and dict == null??
        [treeNode addChild:node];
    }
    [info release];
    if (!moreComing) {
        [self sortAndUpdateUI];
    }
}
Run Code Online (Sandbox Code Playgroud)

bonjour objective-c ios

6
推荐指数
2
解决办法
2348
查看次数

如何在不丢失配置的情况下升级openwrt?

我需要制作一个脚本来升级我的路由器,而不会丢失路由器上安装的配置文件和软件包.

我试图在我的脚本中重复相同的界面行为(我使用命令sysupgrade)但我丢失了配置.

此外,我尝试使用选项保持luci的界面升级,但它也不起作用,我丢失了所有的数据路由器.

sysupgrade命令不保留配置.

有没有人为我提供解决方案?

预先感谢您的帮助.

configuration openwrt firmware

5
推荐指数
1
解决办法
4899
查看次数

"do {free(x); x = NULL;} while(0);"之间的区别是什么?和"{free(x); x = NULL;}"

#define FREE1(x) do { free(x); x = NULL; } while (0);
#define FREE2(x) { free(x); x = NULL; }
Run Code Online (Sandbox Code Playgroud)

这些宏有什么区别?

c

3
推荐指数
2
解决办法
589
查看次数

将十六进制数转换为十进制whith shell脚本

我需要使用shell脚本将数字从十六进制形式转换为十进制形式

例如 :

convert()
{
    ...
    echo x=$decimal
}
Run Code Online (Sandbox Code Playgroud)

结果:

convert "0x148FA1"
x=1347489
Run Code Online (Sandbox Code Playgroud)

怎么做?

shell sh

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

多线程发布安排

我有2个线程来创建thread1和thread2.创建线程时:

pthread_create(&thread1, NULL, &function_th1, NULL);
pthread_create(&thread2, NULL, &function_th2, NULL);
Run Code Online (Sandbox Code Playgroud)

thread2在thread1之前启动,我正在寻找在thread2之前启动thread1的解决方案.

不寻找这个解决方案:

pthread_create(&thread2, NULL, &function_th2, NULL);
pthread_create(&thread1, NULL, &function_th1, NULL);
Run Code Online (Sandbox Code Playgroud)

c linux multithreading

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

如何在printf中显示源代码的行号

可能重复:
C/C++行号

我想显示触发printf的行号?

它可能看起来像这样:

printf("the line number is: %d",SOME_LIBC_MACRO);
Run Code Online (Sandbox Code Playgroud)

怎么做?

c c++

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

标签 统计

c ×6

linux ×3

sh ×2

shell ×2

ash ×1

bash ×1

bonjour ×1

c++ ×1

configuration ×1

firmware ×1

gcc ×1

ios ×1

multithreading ×1

objective-c ×1

openwrt ×1

project ×1

reboot ×1

revision ×1

svn ×1