为什么允许将char类型分配给fgetc?

时间:2019-05-24 15:24:44

标签: c file-io

示例代码:

// C program to illustate fgetc() function 
#include <stdio.h> 

int main () 
{ 
    // open the file 
    FILE *fp = fopen("test.txt","r"); 

    // Return if could not open file 
    if (fp == NULL) 
      return 0; 

    do
    { 
        // Taking input single character at a time 
        char c = fgetc(fp);  // WHY CAN WE DO THIS?

        // Checking for end of file 
        if (feof(fp)) 
            break ; 

        printf("%c", c); 
    }  while(1); 

    fclose(fp); 
    return(0); 
} 

根据文档,fgetc()返回类型为int的值,那么为什么允许我们将char c分配给返回值呢?它和ascii值有关吗?

0 个答案:

没有答案