一、puts ()函数
只要给出字符串参数的地址,并且每一个字符串都是单行显示的
例: #define DEF “I am a #defined string.”
char str1 [80] = “An array was initialized to me.”;
const char * str2 = “A pointer was initialized to me.”;
puts (“I am an argument to puts ().”);
puts (DEF); //I am a #defined string.
puts (str1); //An array was initialized to me.
puts (str2); //A pointer was initialized to me.
puts (&str1 [5]); //ray was initialized to me.
puts (str2 + 4); //inter was initialized to me.
双引号内的字符是字符串常量,看作地址;
字符串的名字也是地址;
&str1[5],地址,数组str1第6个元素开始输出
str2 + 4,地址,指向str2第5个元素所在的内存地址
二、fputs ()函数
格式:fputs (line, stdout);
与puts ()区别:
stdout作为第二个参数,进行输出显示。
fputs ()并不为输出自动添加换行符\n。
gets ()与puts ()搭配使用
fgets ()与fputs ()搭配使用 |
|