| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1718 人关注过本帖
标题:自写printf函数遇到的问题,可变参
取消只看楼主 加入收藏
明明白白
Rank: 2
等 级:论坛游民
帖 子:57
专家分:61
注 册:2012-3-19
结帖率:83.33%
收藏
已结贴  问题点数:5 回复次数:0 
自写printf函数遇到的问题,可变参
#include<stdio.h>
#include<stdarg.h>

void myPrintf(const char *formatStr,...);

void myPrintf(const char *formatStr,...)
{
        va_list begin;
        char ch;
        int i;
        int dh;
        va_start(begin,formatStr);
        for(i = 0;formatStr[i];i++)
        {
                if(formatStr[i] == '%')
                {
                        i++;
                        switch (formatStr[i])
                        {
                                        case 'c':
//提示下面这一行有错误
//myPrintf.c:21:11: warning: ‘char’ is promoted to ‘int’ when passed through ‘...’ //[enabled by default]
//myPrintf.c:21:11: note: (so you should pass ‘int’ not ‘char’ to ‘va_arg’)
//myPrintf.c:21:11: note: if this code is reached, the program will abort

/*******有错误的一行*/                  ch = va_arg(begin,char);
                                        putchar(ch);
                                        break;
                        }
                }
                else
                putchar(formatStr[i]);
        }

}

int main(void)
{
        char first = 'g';
        myPrintf("abcdef%c",first);
        return 0;
}

~                       
搜索更多相关主题的帖子: void case include 
2012-11-17 12:37
快速回复:自写printf函数遇到的问题,可变参
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011320 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved