C - printf() not working but puts() is working fine

前端 未结 3 682
暗喜
暗喜 2021-01-24 23:31
void read_class_information(head* beginning, int scale_type) {
    puts(\"hello\");
    // printf(\"hello\");
}

I have a simple function called by main

3条回答
  •  心在旅途
    2021-01-24 23:47

    Because printf() does not flush the output stream automatically. On the other hand puts() adds a new line '\n' at the end of the passed string. So it's working because the '\n' flushes de stdout.

    Try

    printf("hello\n");
    

    Or, explicitly flush stdout

    fflush(stdout);
    

    right after the printf() statement.

提交回复
热议问题