| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1400 人关注过本帖
标题:gets()连续赋值问题?
只看楼主 加入收藏
talenttao2008
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-5-4
收藏
 问题点数:0 回复次数:3 
gets()连续赋值问题?
定义了一个结构体,里面含有三个字符串,想通过GETS()来对他们实习动态赋值:

结构体为:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define NAME_LEN 20
#define ABBREV_LEN 20
#define GROUP_LEN 20
#define N 11

typedef struct{
               char name[NAME_LEN];
               char abbrev[ABBREV_LEN];
               char group[GROUP_LEN];
               double value;
}unit;

unit s[N]={{"miles","mi","distance",1609.3},{"kilometers","km","distance",1000},{"yards","yd","distance",0.9144},
{"meters","m","distance",1},{"quarts","qt","liquidvolume",0.94635},{"liters","l","liquidvolume",1},{"gallons","gal","liquidvolume",3.7854},
{"milliliters","ml","liquidvolume",0.001},{"kilograms","kg","mass",1},{"grams","g","mass",0.001},{"slugs","slugs","mass",0.14594}};

然后在一个字函数中对结构体的一个新定义变量进行赋值: int scanf_unit(unit *a)
  {
      int d,j=100;
      gets(a->name);gets(a->abbrev);gets(a->group);这里是否有错误?我的语法通过了,但是结果不,并且一定出现在赋值问题上经过我的检查,程序太大,完整的不方便给出,请大家看看解决一下吧,谢谢。
      scanf("lf",&a->value);
      
          for(d=0;d<11;d++)
         if(strcmp(a->name,s[d].name)==0&&strcmp(a->abbrev,s[d].abbrev)==0&&strcmp(a->group,s[d].group)==0)
             j=1;
      return(j);
  }
搜索更多相关主题的帖子: 赋值 gets distance include 
2008-05-06 15:39
talenttao2008
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-5-4
收藏
得分:0 
出现的错误是:
scanf:floating point formats not linked
abnormal program termination
2008-05-06 15:52
now
Rank: 1
来 自:广州
等 级:新手上路
帖 子:544
专家分:0
注 册:2007-11-9
收藏
得分:0 
gets(a->name);gets(a->abbrev);gets(a->group);//此句应该没问题;
scanf("lf",&a->value); //此句就有很大问题;“%”呢?

GIS
Geographic Information System
你在哪里?——》你的坐标?
2008-05-06 18:44
tiw
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2008-2-13
收藏
得分:0 
scanf:floating point formats not linked
abnormal program termination
据说是个tc的bug,哈哈
2008-05-16 16:17
快速回复:gets()连续赋值问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016775 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved