简单的C程序讲解下

来源:百度知道 编辑:UC知道 时间:2024/06/14 11:43:38
#include<stdio.h>
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 m",num);
}
运行结果:
I am a boy
there are 4 words in the line
刚学C的

#include<stdio.h>
main()
{
/* 定义 字元形态 string的阵列,容量为81*/
char string[81];
/* 定义 整数形态 i,num,word 并将 num,word 设初值为0 */
int i,num=0,word=0;
/* 定义 字元形态 c */
char c;
/* 撷取 string 字元阵列 的输入*/
gets(string);
/* str阵列不为空则继续执行囘圈,并将字元 传给 c */
for(i=0;(c=string[i])!=`\0`;i++)
{
/* 若(if) c 等於 空格键 word 的值 则为 0 */
if(c==空格)word==0;
/* 否(else) 并且(if[与 else 一起的时候 意思是如此])
word的值 为 1 并且 num 加 1
*/
else if(word==0)
{
word=1;
num++;
}
}
printf("there are %d words in the line m",num);
}

#include<stdio.h>
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 m",num);
}

#include<std