我有一个文件包含:
aaa.bbbb0.xxxx0=toto
aaa.bbbb0.xxxx1=toto
aaa.bbbb0.xxxx2=titi
eee.ffff.zzzz=kkkk
Run Code Online (Sandbox Code Playgroud)
我想提取包含正则表达式的行"aaa\.bbbb0\.xxxx[0-6]\+=toto",然后提取路径中的第3个元素.所以输出应该以这种方式看待
xxxx
yyyy
Run Code Online (Sandbox Code Playgroud)
我可以使用这个输出grep,然后cut以这种方式:
cat myfile.txt | grep "aaa\.bbbb0\.xxxx[0-6]\+=toto" | cut -d'=' -f1 | cut -d'.' -f3
Run Code Online (Sandbox Code Playgroud)
我怎样才能改变上述grep并且cut仅由一个sed命令或awk指令?
我正在使用以下行在我的 android 应用程序中显示 Toast 消息
Toast.makeText(InitActivity.this, InitActivity.this.getResources().getString(R.string.invalid_pin_code), Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
但是这个消息显示在页面的bootom中。
我想EditText在我的页面下面显示它。
如何做到这一点?
我正在尝试使用以下配置构建 json-c:
./configure --target=arm-linux-androideabi --host=arm-linux-androideabi \
--build=x86_64-unknown-linux-gnu
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
cc1: error: command line option '-std=c++11' is valid for C++/ObjC++ but not for C [-Werror]
Run Code Online (Sandbox Code Playgroud)
我试图添加--disable-std-c++11和--disable-std-cpp11到配置,但我总是遇到同样的问题。
如何解决?
我用open()函数打开一个文件.
我希望该open()函数丢弃文件内容(如果已存在),然后将该文件视为新的空文件.
我尝试使用以下代码:
int open_file(char *filename)
{
int fd = -1;
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (fd < 0) {
printf("Couldn't create new file %s: %s\n",
filename, strerror(errno));
return -1;
}
close(fd);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Couldn't create new file kallel333: File exists
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我有以下代码
#define SWITCH(S) char *_S = S; if (0)
#define CASE(S) } else if (strcmp(_S, S) == 0) {switch(1) { case 1
#define BREAK }
#define DEFAULT } else {switch(1) { case 1
int main()
{
char buf[256];
printf("\nString - Enter your string: ");
scanf ("%s", buf);
SWITCH (buf) {
CASE ("abcdef"):
printf ("B1!\n");
BREAK;
CASE ("ghijkl"):
printf ("C1!\n");
BREAK;
DEFAULT:
printf ("D1!\n");
BREAK;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我生成预处理器代码gcc -E,我将得到以下代码
int main()
{
char buf[256];
printf("\nString - Enter your string: …Run Code Online (Sandbox Code Playgroud) 我有以下代码
long x;
scanf("%ld",&x)
if(x==-1) // does this comparison is allowed
printf("just test\n");
Run Code Online (Sandbox Code Playgroud)
它long的参数需要比较之前的任何铸造?
我打算修改特定字符串的每个其他字母.但就本计划而言,这一切都不会发生.到目前为止,我已经从用户那里抓取了一个字符串并将其存储userinput并打算打印出来.
#include <stdio.h>
#include <string.h>
int main(void) {
char userinput[256] ="";
printf("Enter somthing to change:\n");
scanf("%s", &userinput);
printf("%s\n", userinput);
int k = 2; // This is just here to do something every time k is even
int j = strlen(userinput);
for (int i = 0; i < j; i++) {
if(k % 2 == 0) {
printf("%s", userinput[i]);
k++;
}
else {
printf("%s", userinput[i]);
k++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
strlen()但是该功能不起作用userinput.我strlen()认为这是因为应该获取字符串的第一个字符的地址然后迭代直到达到空字符,但scanf实际上不创建空字符.'\0'在没有先知道字符串的长度的情况下,我无法想出一种在字符串后添加字符串的方法.
如果存储在数组中,我将如何访问存储的字符序列的长度?
我在代码的第一行得到一个奇怪的分段错误.
我只是打电话
FILE *src = fopen(argv[1], 'r');
Run Code Online (Sandbox Code Playgroud)
我在gdb中得到了一条带有错误信息的段错误...
程序接收信号SIGSEGV,分段故障.
0x00007ffff779956d in _IO_file_fopen () from /lib/x86_64-linux-gnu/libc.so.6
Run Code Online (Sandbox Code Playgroud)
我将文件的名称直接复制到运行时执行中.思考?
在C中,我们使用memset()函数将数据设置为0 (不仅用于初始化).
我的数据可以通过另一种方法更改,我想重用它,然后我想在重新使用它之前将其设置为0
有没有其他方法在C++中将数据设置为0而不是memset()?
class MYClass : public NameSpace::ParentClass {
private:
struct mystruct data
public:
void method();
};
void MYClass::method() {
memset(&data, 0, sizeof(data)); // it's the C way. Are there another way in C++
}
Run Code Online (Sandbox Code Playgroud) 我只是尝试使用多线程程序,但我遇到了pthread_join函数的问题.下面的代码只是一个我用来显示pthread_join崩溃的简单程序.此代码的输出将是:
before create
child thread
after create
Segmentation fault (core dumped)
Run Code Online (Sandbox Code Playgroud)
什么原因导致pthread_join给出分段错误?
#include <pthread.h>
#include <stdio.h>
void * dostuff() {
printf("child thread\n");
return NULL;
}
int main() {
pthread_t p1;
printf("before create\n");
pthread_create(&p1, NULL, dostuff(), NULL);
printf("after create\n");
pthread_join(p1, NULL);
printf("joined\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)