c primer plus 8编程练习

 

1、

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int ch;
    FILE * fp;
    char filename[128];
    int sum = 0;
    
    printf("please input filename: ");
    scanf("%s", filename);
    
    fp = fopen(filename, "r");
    
    if(fp == NULL)
    {
        printf("file failed opened!\n");
        exit(1);
    }
    
    while((ch = getc(fp)) != EOF)
    {
        putchar(ch);
        sum++;
    }
    
    printf("\nsum: %d.\n", sum);
    
    return 0;
}

c primer plus 8编程练习

 

#include <stdio.h>

int main(void)
{
    char ch;
    int sum = 0;
    
    while((ch = getchar()) != EOF)
    {
        putchar(ch);
        sum++;
    }
    
    printf("sum: %d.\n", sum);
    
    return 0;
}

c primer plus 8编程练习

 

#include <stdio.h>

int main(void)
{
    char ch;
    int sum = 0;
    
    while((ch = getchar()) != EOF)
    {
        putchar(ch);
        if(ch > \040)
            sum++;
    }
    
    printf("sum: %d.\n", sum);
    
    return 0;
}

c primer plus 8编程练习

 

#include <stdio.h>

int main(void)
{
    char ch;
    int sum = 0;
    
    while((ch = getchar()) != EOF)
    {
        putchar(ch);
        if(ch == \n)
            sum++;
    }
    
    printf("sum: %d.\n", sum);
    
    return 0;
}

c primer plus 8编程练习

 

c primer plus 8编程练习

上一篇:图片字节流和字符串互转,读存图片。


下一篇:自定义Mvc5 Owin 验证