小编rew*_*wed的帖子

C 编程中 (char)getchar() 的函数

我的朋友问我(char)getchar()他​​在一些在线代码中找到了什么,我用谷歌搜索并发现它被使用的结果为 0,我认为常规用法只是ch = getchar(). 这是他找到的代码,谁能解释一下这个函数是什么?

else if (input == 2)
{
    if (notes_counter != LIST_SIZE)
    {
        printf("Enter header: ");
        getchar();
        char c        = (char)getchar();
        int tmp_count = 0;
        while (c != '\n' && tmp_count < HEADER)
        {
            note[notes_counter].header[tmp_count++] = c;
            c = (char)getchar();
        }
        note[notes_counter].header[tmp_count] = '\0';
        
        printf("Enter content: ");
        c         = (char)getchar();
        tmp_count = 0;
        while (c != '\n' && tmp_count < CONTENT)
        {
            note[notes_counter].content[tmp_count++] = c;
            c = (char)getchar();
        }
        note[notes_counter].content[tmp_count] = '\0';
        
        printf("\n"); …
Run Code Online (Sandbox Code Playgroud)

c

2
推荐指数
1
解决办法
179
查看次数

标签 统计

c ×1