我正在尝试自己学习C,我有点困惑getchar和putchar:
#include <stdio.h>
int main(void)
{
char c;
printf("Enter characters : ");
while((c = getchar()) != EOF){
putchar(c);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
#include <stdio.h>
int main(void)
{
int c;
printf("Enter characters : ");
while((c = getchar()) != EOF){
putchar(c);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
C库函数int putchar(int c)将参数char指定的字符(unsigned char)写入stdout.
C库函数int getchar(void)从stdin获取一个字符(一个unsigned char).这相当于以stdin作为参数的getc.
这是否意味着putchar()同时接受int和char或其中一方以及getchar()我们应该使用一个int或char?
我的程序中有一个变量v,它可以从值集中获取任何值
"a", "b", "c", ..., "z"
Run Code Online (Sandbox Code Playgroud)
而我的目标是只有当执行一些说法v是不"x","y"或"z".
我试过了,
对于类C语言(其中相等运算符比较实际的字符串值;例如.c#,javascript,php)
if (v != "x" || v != "y" || v != "z")
{
// the statements I want to be executed
// if v is neither "x", nor "y", nor "z"
}
Run Code Online (Sandbox Code Playgroud)用于Pascal类语言(例如plsql)
IF (v != 'x' OR v != 'y' OR v != 'z') THEN
-- the statements …Run Code Online (Sandbox Code Playgroud)language-agnostic if-statement multiple-languages control-flow