编写一个程序:该程序读取输入知道遇到#字符,然后报告读取的空格数目、读取的换行符数目

来源:百度知道 编辑:UC知道 时间:2024/05/12 17:45:29
读取还有其他字符数目

#include "stdio.h"
struct string
{
char chr;
struct string *next;
};
main()
{
int i=0,j=0;
struct string *str,*head;
head=str=(struct string *)malloc(sizeof(struct string));
str->chr='\0';
while(str->chr!='#')
{
str->chr=getch();
if(str->chr!='#' && str->chr!='\r')putchar(str->chr);
else if(str->chr=='\r')putchar('\n');
if(str->chr=='\r')i++;
else if(str->chr==' ')j++;
if(str->chr!='#')
str=str->next=(struct string *)malloc(sizeof(struct string));
}
printf("\nnumber of space is %d\n",j);
printf("number of enter if %d",i);
getch();
}