我有:
char *str = "abc def abcdef ghi xyz";
Run Code Online (Sandbox Code Playgroud)
我想分配
const char *a = "abc";
const char *b = "def";
const char *c = "abcdef";
const char *d = "ghi";
const char *e = "xyz";
Run Code Online (Sandbox Code Playgroud)
这里的关键是空格数可以多于一个.
请建议一个有效的方法.
我需要看看我的string
匹配是否是"你好X",其中X是任意的int
.
基本上我想要抓住它的"你好1"或"你好100".
我怎么能做到最好?
编辑0
谢谢Andrea Bergia.
我正在使用你的代码:
int dummy;
if (sscanf(string, "hello %d", &dummy))
/* matched */
Run Code Online (Sandbox Code Playgroud) 让我说我正在做mk"目标"来构建一些东西.有可能传递一个参数吗?即mk"目标""x",它会做相应的事情吗?我知道我将提供mk"target"一个参数,我知道它的语义,只是提前不知道这个名字.
可能?
我table view
作为主屏幕有4行.首先,我想禁用滚动细胞up
和down
.其次,我想在第4个单元格中添加徽标图像.
谁能建议我这样做的正确方法?
提前致谢.
动机:将结构传递给函数,例如我们可以在任何函数中更改它并检索任何函数中的任何值.
我从以下网站获取了这些代码:http://cboard.cprogramming.com/c-programming/126381-passing-structure-reference-through-4-functions.html#post942397
我调整了一点,这里是:
struct_passing.h
typedef struct thing {
char *x;
}thing_t;
struct_passing.c
#include <stdio.h>
#include "struct_passing.h"
void f4(thing_t *bob) {
bob->x = "changed";
}
void f3(thing_t *bob) {
f4(bob);
printf("inside f3 x: %s\n", bob->x);
}
void f2(thing_t *bob) {
f3(bob);
}
void f1(thing_t *bob) {
f2(bob);
}
int main(void) {
thing_t foo;
foo.x = "same";
printf("Before: %s\n", foo.x);
f1(&foo);
printf("After: %s\n", foo.x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它在ubuntu上的**gcc版本4.4.3上按预期工作
$ gcc -o struct struct_passing.c
$ ./struct
Before: same
inside f3 …
Run Code Online (Sandbox Code Playgroud) 我想确保项目完全配置为C (NOT C++).这样做我找不到任何准确的步骤.我愿意使用Eclipse
,除了它没有创建一个开箱即用的工作项目(这没有意义......).
我正在尝试写一个简单的函数调用时遇到一些问题; 基本上,该函数采用string
和character
参数,并返回pointer
到first instance
该字符的的字符串中.此实例中的调用使用for循环来使用指向字符串的指针来打印出4个字符串.我试过摆弄一堆东西,但无法获得功能并打电话去工作.任何帮助将不胜感激.
#include <stdio.h>
#define NUMBER 4
char * strsrch(char * string, char x);
int main(void)
{
char * ptr[NUMBER];
int x;
char * word[NUMBER] = {"This is string 1", "Now string 2", "Proceeding through string 3", "And then, the last string"};
for(x = 0; x < NUMBER; x++)
puts(word[x]);
for(x = 0; x < NUMBER; x++)
puts(strsrch(word[x], 'i'));
return 0;
}
char * strsrch(char * string, char x)
{
while …
Run Code Online (Sandbox Code Playgroud) 我怎样才能在C中使用这个正则表达式?
如果我这样做,我会收到错误:
if (regcomp(®, "/[^\\]\]/", REG_EXTENDED | REG_ICASE) != 0)
Run Code Online (Sandbox Code Playgroud)
错误:
warning: unknown escape sequence '\]'
Run Code Online (Sandbox Code Playgroud)
提前致谢.
这是我想要匹配的字符串
str ="hello_my_world";
regex_t reg;
if (regcomp(®, pattern, REG_EXTENDED | REG_ICASE) != 0) {
exit (-1);
}
if (regexec(®, str, 0, NULL, 0) != 0) {
regfree(®);
/* did not match */
}
regfree(®);
}
Run Code Online (Sandbox Code Playgroud)
如果是模式,hello_*
则返回true.但如果模式hello_*_world
不是......那是预期的吗?
我怎么能匹配呢?
dir1有dir2、file1.c和file1.h。
dir2 有 file2.c
现在,如果我想在 file2.c 中访问 file1.c 中定义的函数,我需要在 file1.h 中声明它并在 file2.c 中包含 file1.h ——这是一个有效的假设吗?
如果不是,请解释一下。
如果是,即使这样做之后我也会收到“未定义的函数引用”错误。
file2.c:29: 对“函数”collect2 的未定义引用:ld 返回 1 退出状态 *错误代码 1
默认情况下,全局变量初始化为"0".
当我明确地为其赋值"0"时,它会产生多大的差异(如果有的话).
他们中的任何一个是更快/更好/更优化?
我尝试了一个小样本.c程序,但我没有看到可执行文件大小的任何变化.
编辑:0我只想了解行为.它在任何方面都不是我的瓶颈.