本文介绍了得到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 因为某些原因比较我的函数中的文字有问题我的 代码在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} 解决方案 [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 { switch(i) { case 0 : 得到(inp); delay = atoi(inp); 休息; 默认值: i = 3; 休息; } ++ i; } } } 我会回复批评,所以代码和我的评论显然是 由"区分。 - Andrew Poelstra< http://www.wpsoftware。 net> 对于电子邮件,请在上述网站上使用'apoelstra'。 你在外面只是聪明。 -anon。 您是否尝试使用键盘输入或 来自文件填充数组,我认为gets()用于通过键盘和fgets输入来自文件的 ...希望它有所帮助。 不,它没有。第一个编译时错误发生在fgets。 嗯,你当时并不擅长隔离。 [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); 呃... * snd是一个字符。 strcmp想要一个指向char的指针。如果你有 包括< string.hyou就知道了。 同上。 这个snippit有很多问题我只会 重写整个事情: fgets(inp,sizeof inp,stdin); delay = atoi(inp); } } (我也被分配值4,但它''失去了作为功能n结束。) - Andrew Poelstra< http://www.wpsoftware.net> 电子邮件,在上面的网站上使用''apoelstra'。 你在外面只是聪明。 -anon。 Hi,have a problem with comparing text in my function for some reason mycode get hang at fgets.i am uploading this code in an IC, but i have isolated the problem tofgets(SettingInfo);could anyone help methank you 1void rxtx()2{34const char RequestSet[]="SET"; //SET SYStem INFOrmation5const char RequestSnd[]="REQ";// SeND SYStem INFOrmation6char SettingInfo[30];78fgets(SettingInfo);9 printf("got info %s",SettingInfo);1011if(strcmp(SettingInfo, *RequestSnd)== 0) {1213 SendSetting();1415}161718if(strcmp(SettingInfo, *RequestSet) == 0){1920int xacounter=0;2122 while(xacounter <= 1){2324 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 }3536 xacounter = xacounter + 1;37 }38}39} 解决方案 [snipped "code"] You need to learn C, especially the fgets() function. Here is your code, with formatting, variable names, comments, andoperator 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 clearlydifferentiated 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. Hi,Are you trying to fill in the array with input from Keyboard orfrom file, i think gets() is used for inputs through keyboard and fgetsfrom file... Hope it helps. No it doesn''t. The first compile-time error is at fgets. Well, you aren''t very good at isolating, then. [snipped "code"]You need to learn C, especially the fgets() function.Here is your code, with formatting, variable names, comments, andoperator 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); Uh... *snd is a char. strcmp wants a pointer to char. If you hadincluded <string.hyou would know that. Ditto. There are so many things wrong with that snippit that I''ll justrewrite 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. 这篇关于得到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 07:42