This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28027: 关于printf使用\r,\n打印效果的询问

Part Number: TMS320F28027

例如:

1.printf("\r\nHello,World!");

2.printf("\rHello,World!");

3.printf("\nHello,World!");

上面三种打印效果是否一样?

CCS中使用printf有哪些与标准的C不同?

谢谢!

  • Hi,

    以下是我的测试结果,使用的是CCS的控制台来查看打印结果:

    1. 

    2. 

    3. 

    从显示来看测试结果是相同的,但是2(单纯使用\r)会很卡(可以看到卡在o后面了,刷新不及时),其余两个显示会很流畅;

    CCS中使用printf有哪些与标准的C不同?

    标准上来说没什么不同,只是有一些点需要注意,比如要配置堆栈的大小(主要是用作IO的缓冲区域)。

    另外比较下来,使用printf占用资源会比较多(主要是内存方面),而puts的占用会比较小:

    printf:

    puts:

    none:

    三者的区别只是有无添加:

    Fullscreen
    1
    2
    #include <stdio.h>
    puts("Hello, world!");
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Fullscreen
    1
    2
    #include <stdio.h>
    printf("\nHello, world!");
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    另外puts不需要添加任何参数便可以实现流畅的换行。