newb:输入int-s [英] newb: inputting int-s

查看:72
本文介绍了newb:输入int-s的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全是编程的新手,非常感谢一些帮助。


该程序需要能够采取一组最多100个数字(
之间)
1到9)在输入提示时输入

,然后单独分配这些数字以分离

变量然后传递到另一个将执行的函数其他

对数字的操作。


char line [200]


printf("输入数字:); //数字将按空格分隔

fgets(gridEmulation,sizeof(gridEmulation),stdin); //得到数字


在这里我卡住了,我想用sscanf将输入值转换回b / b
回到个别数字,但怎么做我指的是这个数字,当我不知道
时,甚至知道会有多少。


TIA


ASiF

Hi i am completely novice at programming, would appreciate some help.

The program needs to be able to take a set of up to a 100 numbers (between
1 to 9) "inputted"
at the prompt and then assign those number indvidually to seperate
variable and then pass on to another function which will perform other
operations on the numbers.

char line[200]

printf ("Enter the numbers: "); //numbers would be seperated by space
fgets (gridEmulation, sizeof(gridEmulation), stdin); //gets in the numbers

here i get stuck, i was thinking of using sscanf to turn the input vales
back to individual numbers, but how do i assign the number when i dont
even know how many there are going to be.

TIA

ASiF

推荐答案

" ASiF" <所以*** @的localhost.localdomain> ha scritto nel messaggio

news:bj ********** @ tomahawk.unsw.edu.au ...
"ASiF" <so***@localhost.localdomain> ha scritto nel messaggio
news:bj**********@tomahawk.unsw.edu.au...
嗨我完全是新手编程,会感激一些帮助。

该程序需要能够采取一组最多100个数字(在
1到9之间)输入
提示然后将这些数字单独分配给单独的变量,然后传递给另一个将对数字执行其他操作的函数。

char line [200]

printf("输入数字:"); //数字将由空格分隔
fgets(gridEmulation,sizeof(gridEmulation),stdin); //得到数字

这里我卡住了,我想用sscanf将输入值转回单个数字,但是当我不<时如何分配数字?或者知道会有多少。

TIA

ASiF
Hi i am completely novice at programming, would appreciate some help.

The program needs to be able to take a set of up to a 100 numbers (between
1 to 9) "inputted"
at the prompt and then assign those number indvidually to seperate
variable and then pass on to another function which will perform other
operations on the numbers.

char line[200]

printf ("Enter the numbers: "); //numbers would be seperated by space
fgets (gridEmulation, sizeof(gridEmulation), stdin); //gets in the numbers

here i get stuck, i was thinking of using sscanf to turn the input vales
back to individual numbers, but how do i assign the number when i dont
even know how many there are going to be.

TIA

ASiF




循环on gridEmulation:


在每个循环中你都可以:


使用strtok()并对返回的每个令牌执行sscanf()





使用仅有一个%d的sscanf()传递给它

& gridEmulation [i]但每次你必须增加我b $ b,直到你到达一个空间。


再见,

Ema



By a loop on gridEmulation:

At every loop you can:

use strtok() and execute sscanf() on every token returned

or

use sscanf() with only one "%d" passing to it
&gridEmulation[i] but every time you have to
increase i until you reach a space.

Bye,
Ema


>>
printf(" ;输入数字:"); //数字将由空格分隔
fgets(gridEmulation,sizeof(gridEmulation),stdin); //得到数字

这里我卡住了,我想用sscanf将输入值转回单个数字,但是当我不<时如何分配数字?或者知道会有多少。

TIA

ASiF
printf ("Enter the numbers: "); //numbers would be seperated by space
fgets (gridEmulation, sizeof(gridEmulation), stdin); //gets in the numbers

here i get stuck, i was thinking of using sscanf to turn the input vales
back to individual numbers, but how do i assign the number when i dont
even know how many there are going to be.

TIA

ASiF



通过gridEmulation上的循环:

在每个循环中你都可以:

使用strtok()并对返回的每个令牌执行sscanf()


使用仅有一个%d的sscanf()传递给它
& gridEmulation [i]但每次你必须增加我直到你到达一个空间。

再见,
Ema



By a loop on gridEmulation:

At every loop you can:

use strtok() and execute sscanf() on every token returned

or

use sscanf() with only one "%d" passing to it
&gridEmulation[i] but every time you have to
increase i until you reach a space.

Bye,
Ema




感谢艾玛,试了一下。工作得很漂亮!

你是一个传奇!



Thanks emma, tried it out. Works beautifully!
You are a legend!


ASiF写道:
ASiF wrote:
你好我完全编程的新手,会很感激一些帮助。
Hi i am completely novice at programming, would appreciate some help.




你的意思是C是你的第一语言吗?我不推荐。


-

Tom Zych

这个电子邮件地址将在某个时候到期以阻止垃圾邮件发送者。

永久地址:echo''g******@cbobk.pbz''| rot13



Do you mean C is your first language? I wouldn''t recommend that.

--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo ''g******@cbobk.pbz'' | rot13


这篇关于newb:输入int-s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆