1.
#include <stdio.h> #define SPACE ' '
#define NEWLINE '\n' int main()
{
int spaces,newlines,others;
char ch;
spaces = newlines = others = ;
while((ch=getchar())!= '#')
{
/*
if(ch == SPACE)
{
spaces++;
}else if(ch == NEWLINE)
{
newlines++;
}else
{
others++;
}*/
switch(ch)
{
case SPACE:
spaces++;
break;
case NEWLINE:
newlines++;
break;
default:
others++;
break;
}
}
printf("spaces=%d, newlines=%d, others=%d \n", spaces, newlines, others);
getchar();
return ;
}
2.
#include <stdio.h> int main()
{
int i;
char ch;
printf("quit input #");
for(i=; (ch=getchar())!='#'; i++)
{
printf("%c -- %d \t", ch, ch);
if(i% == ){
printf("\n");
}
}
getchar();
return ;
}