C语言练习笔记更新

字符串处理函数

puts()和gets()

#include<stdio.h>
void main()
{
 char str[10];
 gets(str);
 puts(str);
}

strcat函数

其一般形式为strcat(字符数组1,字符数组2)

=号返回的是=右边的值。

检查输入有多少个单词:

#include<stdio.h>
void main()
{
 char string[81];
 int i, num = 0, word = 0;
 char c;
 gets(string);
 for(i = 0; (c = string[i])!= '\0'; i++)
 {
  if(c== ' ')
   word = 0;
  else if (word == 0)
  {
   word = 1;
   num++;
  }
 }
 printf("There are %d words in the line.\n",num);
}

原文地址:https://www.cnblogs.com/tao560532/p/2335030.html