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);
}