C 编程:如何打印作为参数传递的字符值

C programming : How to print a character value passed as a parameter

例如有一个方法dog:

void dog(char C,int N)
{
//here if I want to print the value of C with a print statement,how do I do that?
}

一个怎么样

printf("the value of c = %c\n", C);

有几种方法可以做到这一点。

假设 char c 中存储的值是字母 "H"。

如果您只想查看值,最基本的方法将要求您使用 putchar

putchar(c);

putchar 只会给你 c 的值和一个换行符。

所以它会打印出来:

H

但是,如果您希望值与其他文本在同一行中,您可以使用 printf:

printf("The value stored in C is: %c\n", C);

它会打印出:

The value stored in C is: H

printf让你在文本行中添加值,但是没有换行符,所以你必须像我一样自己添加一个。

希望一切都清楚一些。

这样做

void dog(char C,int N)
{
    fprintf(stdout, "C = %c N = %d\n", C, N );
}