开发者

How to prompt and wait for next command in order to continue

I've created a command line tool that parses JSON from reddit's front page. After being able to successfully list all of the submission titles; I want to be able to prompt and wait for numeric selection to go deeper into the post.

Btw, I'm fairly new to the language and I'm creating this for fun. I don't really know how to even properly ask this question because I've never developed for a comp开发者_JS百科iler.


What about plain ol' C:

int selection;
do
{
    fseek(stdin, 0, SEEK_END);
    printf("Select and ID: ");
}
while (scanf("%i", &selection) == 0);

Sorry that I have no method for you to check out. However, you may at your discretion read the man page for scanf (and for fseek, now that I added it— sorry for the non-working snippet earlier!). If you want a small exercise, try to find out why it's necessary to have the fseek call.

Though don't forget to #include <stdio.h>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜