简体   繁体   English

如何使目标c控制台行垂直输出?

[英]How to make objective c console line vertical output?

Here's my understanding fetching the input: 这是我对获取输入的理解:

int num = 0;
NSLog (@"Input 5 numbers");

scanf("%d", &num);


NSLog (@"\n You inputted: %d !", num);

Sample Input: 54321 Output: 54321 样本输入:54321输出:54321

But the output should be: 但是输出应该是:
5
4 4
3 3
2 2
1 1

I see no one-line-code solution here. 我在这里看不到任何一行代码的解决方案。 It can be achieved with for or while loop. 它可以通过forwhile循环来实现。 eg you may divide num by 10 or convert it to string and fetch each character. 例如,您可以将num除以10或将其转换为字符串并获取每个字符。

For an example of converting an NSString to a char array see here . 有关将NSString转换为char数组的示例, 请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM