小编0x0*_*584的帖子

使用带有可变参数的函数(va_list)打印字符串

我正在尝试打印参数变量类型字符串,但我一直坚持这个

想法

尝试_Str[i]在 while 循环中使用as 表达式在srting 内部移动,并且一旦_Str[i] == '\0'返回(-1)定义为EOF之后我们测试'\n' == EOF返回EOF。比切换到下一个变量

编码

主文件

int main(int argc, char** argv)
{ 
    ps("test1", "test2");
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

基数

#ifndef BASE_H_
 #define BASE_H_
  #ifndef EOF // (EOF) - End Of File character. (-1)
   #define EOF (-1)
  #endif// EOF 
 #include<stdio.h>// Facultatif  
 #include<stdarg.h> 

    int ps(const char* , ...); // our function


#endif // BASE_H_
Run Code Online (Sandbox Code Playgroud)

基地.c

int ps(const char* _Str, ...)
{
    int  i = 0;

    //char* …
Run Code Online (Sandbox Code Playgroud)

c string pointers variadic-functions

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

标签 统计

c ×1

pointers ×1

string ×1

variadic-functions ×1