得到问题 [英] gets problem

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

问题描述



因为某些原因比较我的函数中的文字有问题我的

代码在fgets上挂起。

i上传这个代码在IC中,但是我把问题隔离到了

fgets(SettingInfo);

可以有人帮我吗

谢谢你/>

1无效rxtx()

2 {

3

4 const char RequestSet [] =" ; SET英寸; // SET SYStem INFOrmation

5 const char RequestSnd [] =" REQ" ;; // SeND SYStem INFOrmation

6 char SettingInfo [30];

7

8 fgets(SettingInfo);

9 printf(获取信息%s,SettingInfo);

10

11 if(strcmp(SettingInfo,* RequestSnd)== 0){

12

13 SendSetting();

14

15}

16

17

18 if(strcmp(SettingInfo,* RequestSet)= = 0){

19

20 int xacounter = 0;

21

22 while(xacounter< = 1){

23

24开关(xacounter)

25 {

26案例0:{

27得到(SettingInfo);

28 Set_ms_delay = atoi(SettingInfo);

29 break;

30}

31默认值:

32 xacounter = 3;

33休息;

34}

35

36 xacounter = xacounter + 1;

37}

38}

39}

解决方案

On Sun,2006-12-11 at 21:54 -0800,Zulander写道:



$ b因为某些原因,$ b在我的函数中比较文本时遇到问题我的

代码在fgets上挂起。

i我在IC上传这段代码,但是我已经隔离了问题

fgets(SettingInfo);

任何人都可以帮助我

谢谢



[snipped" code]


你需要学习C,特别是fgets()函数。


这是你的代码,格式化,变量名称,注释和

操作员滥用纠正:


void myfunc(void)

{

const char snd [] =" REQ" ;; / * SeND系统信息* /

const char set [] =" SET" ;; / *设置系统信息* /

char inp [30];


fgets(inp);

printf("获得信息:%s",inp);


if(strcmp(inp,* snd)== 0)

SendSetting();


if(strcmp(inp,* set)== 0)

{

int i = 0;

while(i <= 1)

{

switch(i)

{

case 0 :

得到(inp);

delay = atoi(inp);

休息;

默认值:

i = 3;

休息;

}

++ i;

}

}

}


我会回复批评,所以代码和我的评论显然是

由"区分。


-

Andrew Poelstra< http://www.wpsoftware。 net>

对于电子邮件,请在上述网站上使用'apoelstra'。

你在外面只是聪明。 -anon。



6 char SettingInfo [30];

7

8 fgets(SettingInfo);

9 printf("获取信息%s",SettingInfo);





您是否尝试使用键盘输入或

来自文件填充数组,我认为gets()用于通过键盘和fgets输入
来自文件的
...希望它有所帮助。


On星期一,2006-13-11在06:17 +0000,Andrew Poelstra写道:


On Sun,2006-12-11 at 21:54 -0800,Zulander写道:




由于某种原因比较我的函数中的文本有问题我的

代码得到了fgets。



不,它没有。第一个编译时错误发生在fgets。


i我在IC中上传此代码,但我已将问题隔离到

fgets(SettingInfo);



嗯,你当时并不擅长隔离。


任何人都可以帮助我

谢谢



[snipped" code"]


你需要学习C,特别是fgets()函数。


这是你的代码,包含格式,变量名,注释和

操作员滥用纠正:


void myfunc(无效)

{

const char snd [] =" REQ英寸; / * SeND系统信息* /

const char set [] =" SET" ;; / * SET系统信息* /

char inp [30];


fgets(inp);



1.包括< stdio.h> ;.

2.对fgets()使用正确的语法:

fgets(inp,sizeof inp,stdin);


printf("获取信息:%s",inp);

if(strcmp(inp,* snd)== 0)

SendSetting();



呃... * snd是一个字符。 strcmp想要一个指向char的指针。如果你有

包括< string.hyou就知道了。


>

if(strcmp (inp,* set)== 0)



同上。


{

int i = 0;

while(i <= 1)

{

switch(i)

{

案例0:

得到(inp);

delay = atoi(inp);

休息;

默认:

i = 3;

休息;

}

++ i;

}



这个snippit有很多问题我只会

重写整个事情:


fgets(inp,sizeof inp,stdin);

delay = atoi(inp);
< blockquote class =post_quotes>
}

}



(我也被分配值4,但它''失去了作为功能n结束。)


-

Andrew Poelstra< http://www.wpsoftware.net>

电子邮件,在上面的网站上使用''apoelstra'。

你在外面只是聪明。 -anon。


Hi,
have a problem with comparing text in my function for some reason my
code get hang at fgets.
i am uploading this code in an IC, but i have isolated the problem to
fgets(SettingInfo);
could anyone help me
thank you

1 void rxtx()
2 {
3
4 const char RequestSet[]="SET"; //SET SYStem INFOrmation
5 const char RequestSnd[]="REQ";// SeND SYStem INFOrmation
6 char SettingInfo[30];
7
8 fgets(SettingInfo);
9 printf("got info %s",SettingInfo);
10
11 if(strcmp(SettingInfo, *RequestSnd)== 0) {
12
13 SendSetting();
14
15 }
16
17
18 if(strcmp(SettingInfo, *RequestSet) == 0){
19
20 int xacounter=0;
21
22 while(xacounter <= 1){
23
24 switch(xacounter)
25 {
26 case 0:{
27 gets(SettingInfo);
28 Set_ms_delay=atoi(SettingInfo);
29 break;
30 }
31 default:
32 xacounter=3;
33 break;
34 }
35
36 xacounter = xacounter + 1;
37 }
38 }
39 }

解决方案

On Sun, 2006-12-11 at 21:54 -0800, Zulander wrote:

Hi,
have a problem with comparing text in my function for some reason my
code get hang at fgets.
i am uploading this code in an IC, but i have isolated the problem to
fgets(SettingInfo);
could anyone help me
thank you

[snipped "code"]

You need to learn C, especially the fgets() function.

Here is your code, with formatting, variable names, comments, and
operator abuse corrected:

void myfunc(void)
{
const char snd[] = "REQ"; /* SeND system information */
const char set[] = "SET"; /* SET system information */
char inp[30];

fgets(inp);
printf("Got info: %s", inp);

if(strcmp(inp, *snd) == 0)
SendSetting();

if(strcmp(inp, *set) == 0)
{
int i = 0;
while(i <= 1)
{
switch(i)
{
case 0:
gets(inp);
delay = atoi(inp);
break;
default:
i = 3;
break;
}
++i;
}
}
}

I''ll reply with critique, so that the code and my comments are clearly
differentiated by the ""''s.

--
Andrew Poelstra <http://www.wpsoftware.net>
For email, use ''apoelstra'' at the above site.
"You''re only smart on the outside." -anon.


6 char SettingInfo[30];
7
8 fgets(SettingInfo);
9 printf("got info %s",SettingInfo);


Hi,
Are you trying to fill in the array with input from Keyboard or
from file, i think gets() is used for inputs through keyboard and fgets
from file... Hope it helps.


On Mon, 2006-13-11 at 06:17 +0000, Andrew Poelstra wrote:

On Sun, 2006-12-11 at 21:54 -0800, Zulander wrote:

Hi,
have a problem with comparing text in my function for some reason my
code get hang at fgets.

No it doesn''t. The first compile-time error is at fgets.

i am uploading this code in an IC, but i have isolated the problem to
fgets(SettingInfo);

Well, you aren''t very good at isolating, then.

could anyone help me
thank you

[snipped "code"]

You need to learn C, especially the fgets() function.

Here is your code, with formatting, variable names, comments, and
operator abuse corrected:

void myfunc(void)
{
const char snd[] = "REQ"; /* SeND system information */
const char set[] = "SET"; /* SET system information */
char inp[30];

fgets(inp);

1. Include <stdio.h>.
2. Use the proper syntax for fgets():
fgets(inp, sizeof inp, stdin);

printf("Got info: %s", inp);

if(strcmp(inp, *snd) == 0)
SendSetting();

Uh... *snd is a char. strcmp wants a pointer to char. If you had
included <string.hyou would know that.

>
if(strcmp(inp, *set) == 0)

Ditto.

{
int i = 0;
while(i <= 1)
{
switch(i)
{
case 0:
gets(inp);
delay = atoi(inp);
break;
default:
i = 3;
break;
}
++i;
}

There are so many things wrong with that snippit that I''ll just
rewrite the whole thing:

fgets(inp, sizeof inp, stdin);
delay = atoi(inp);

}
}

(i is also assigned the value 4, but it''s lost as the function ends.)

--
Andrew Poelstra <http://www.wpsoftware.net>
For email, use ''apoelstra'' at the above site.
"You''re only smart on the outside." -anon.


这篇关于得到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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