putchar(getchar())函数运用
程序:
#include<stdio.h>
int main()
{
putchar(getchar()); /*将键盘输入的字符直接输出到屏幕 (只能输出一个字符)*/
return 0;
}
输出结果1:
a
a
--------------------------------
Process exited with return value 0
Press any key to continue . . .
输出结果2:
abcd
a
--------------------------------
Process exited with return value 0
Press any key to continue . . .
puts()函数运用
程序:
#include<stdio.h>
int main()
{
char a[]={"abcde"};
puts(a);
return 0;
}
输出结果:
abcde
--------------------------------
Process exited with return value 0
Press any key to continue . . .
**
用printf()函数输出字符串
**
程序:
#include<stdio.h>
int main()
{
char a[]="abcde";
printf("%s",a);
return 0;
}
输出结果:
abcde
--------------------------------
Process exited with return value 0
Press any key to continue . . .
**
字符串复制函数strcpy()的运用
**
程序:
#include<stdio.h>
#include<string.h>
int main()
{
char a[]="123456789";
strcpy(a+4,"hello"); /*把字符"hello"复制到a+4(数字串a第四位之后)开始的地方 */
puts(a);
return 0;
}
输出结果:
1234hello
--------------------------------
Process exited with return value 0
Press any key to continue . . .
**
strncpy()函数运用
**
程序:
#include<stdio.h>
#include<string.h>
int main()
{
char a[]="abcdefg",a2[]="ABCDEF";
strncpy(a,a2,4); /* 用字符串2的前n位字符替换掉字符串1的前n位 */
puts(a);
return 0;
}
输出结果:
ABCDefg
--------------------------------
Process exited with return value 0
Press any key to continue . . .