我一直在寻找答案,但找不到任何可以运行此代码的内容。我得到av[1]的声明中main函数时,编译器强调:
static char const *str = av[1];
Run Code Online (Sandbox Code Playgroud)
这是我尝试使用 gcc 运行的代码:
#include <stdio.h>
#include <stdlib.h>
char *ft_strjoin(char const *s1, char const *s2);
void fct(char **av)
{
static char const *str = av[1];
str = ft_strjoin(av[1], av[1]);
printf("%s\n", str);
}
int main(int ac, char **av)
{
fct(&av[1]);
fct(&av[1]);
fct(&av[1]);
fct(&av[1]);
fct(&av[1]);
fct(&av[1]);
}
Run Code Online (Sandbox Code Playgroud)
我发现这 很有趣,但我仍然不明白,也不知道如何运行这段代码。
c static compiler-errors initialization compile-time-constant
我对我编写的程序有疑问.该程序将进入if语句,而不应该.我有两个变量:
size_t len = 5;
int tmp = -1;
Run Code Online (Sandbox Code Playgroud)
当我做 :
if (tmp > len)
ft_putstr("this is crazy");
Run Code Online (Sandbox Code Playgroud)
我打印出"这很疯狂,而-1比我小5!好的,好的.所以我看了我最喜欢的网站,看到了这个.
尝试时:
printf("%zu", tmp)
Run Code Online (Sandbox Code Playgroud)
我看到一个很大的正数.好 !这可能是我的程序进入上述if条件的原因,但是如何让它不进入if条件?谢谢
我试图重新编码一个printf函数,所以我需要使用,va_arg因为printf是一个可变函数.
问题是,当我想打印出参数时my_printf,如果我们采用这两种基本可能性,它们可以是%i(int)或%s(char *).
因此,当我浏览我的时候va_list ap,我试图在va_arg函数中添加一个变量,以便我可以更改要写入的类型,如下所示:
char *str = NULL;
str = ft_set_my_types(flags[cur_arg]);
ft_putstr(va_arg(ap, str));
Run Code Online (Sandbox Code Playgroud)
我的功能ft_set_my_types是这样的:
char *ft_set_my_types(char *flags)
{
char **tab = NULL;
tab = ft_alloc_mem2(2, 15); /* this function malloc a tab */
char a = 65;
/* the example here is only with two types of variables */
/* I am sending flags %s in my …Run Code Online (Sandbox Code Playgroud)