Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 C 新手,我正在尝试编写一个使用递归缩进行的函数。我一直在想办法做到这一点,但我无法弄清楚。
文本应如下所示:
This is a text This is a text This is a text
只需将缩进级别传递给您的递归函数,并在您进行递归调用时将其增加一。
void indent( const char * text, int level, int limit ) { if( level >= limit ) return; printf( "%*s%s\n", level * 4, "", text ); indent( text, level + 1, limit ); }
调用为:
indent( "This is a text", 0, 3 );