如何打印字符* [英] How to print char *

查看:80
本文介绍了如何打印字符*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印char *名称;

I am trying to print char * name;

我尝试过

fprintf(stderr,"%c",* name)

但是它似乎不起作用.我的理由是,由于名称是字符指针,因此我可以使用*来获取指针的值.

But it doesn't seem to work. My reasoning was that since name is a character pointer I could use * to get the value for the pointer.

它给出了错误错误:格式指定类型为'char *',但参数的类型为'char'

It gives the error error: format specifies type 'char *' but the argument has type 'char'

推荐答案

您在这里

#include <stdio.h>

int main(void) 
{
    char *name = "TriposG";

    fprintf( stderr, "%s", name );

    return 0;
}

至此声明

fprintf( stderr, "%c", *name);

然后输出指针 name 所指向的字符串的第一个字符.

then it outputs the first character of the string pointed to by the pointer name.

这篇关于如何打印字符*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆