D
Dominic Grosleau
When i tried to compile this test driver for an actual conversion library
i'm trying to make I got the following messages from gcc.
/*problems reported*/
gcc convertlib.c main.c -ansi -pedantic
main.c:21:22: warning: character constant too long
main.c:22:41: warning: multi-character character constant
main.c: In function `convert':
main.c:22: warning: comparison is always false due to limited range of data type
main.c:22:61: warning: multi-character character constant
main.c:22: warning: comparison is always false due to limited range of data type
What i really want is for the convert() function in main() to behave correctly to
the way i'm passing its parameter.
I'm guessing i screwed up somewhere in the convertlib.h definition or in
the main.c convert() implementation...
Please help !!!
/* main.c */
#include <stdio.h>
#include "convertlib.h"
int main()
{
int result = 0;
result = convert(12, "imperial", "inch", "feet");
printf("\n12 imperial inches = %d feet\n", result);
return 0;
}
int convert(int unit, const char *sys, const char *initial, const char *final)
{
int success = 0;
switch(*sys)
{
case 'imperial':
if (*initial == 'inch' && *final == 'feet')
success = conv_inch2feet(unit);
default:
success = 1;
};
return success;
}
/*convertlib.h*/
#define FOOT 12 /* # of inches in a foot
int conv_inch2feet(int inch);
int convert(int unit, const char *,const char *,const char *);
/*convertlib.c*/
int conv_inch2feet(int inch)
{
feet = inch / FOOT;
return feet;
}
i'm trying to make I got the following messages from gcc.
/*problems reported*/
gcc convertlib.c main.c -ansi -pedantic
main.c:21:22: warning: character constant too long
main.c:22:41: warning: multi-character character constant
main.c: In function `convert':
main.c:22: warning: comparison is always false due to limited range of data type
main.c:22:61: warning: multi-character character constant
main.c:22: warning: comparison is always false due to limited range of data type
What i really want is for the convert() function in main() to behave correctly to
the way i'm passing its parameter.
I'm guessing i screwed up somewhere in the convertlib.h definition or in
the main.c convert() implementation...
Please help !!!
/* main.c */
#include <stdio.h>
#include "convertlib.h"
int main()
{
int result = 0;
result = convert(12, "imperial", "inch", "feet");
printf("\n12 imperial inches = %d feet\n", result);
return 0;
}
int convert(int unit, const char *sys, const char *initial, const char *final)
{
int success = 0;
switch(*sys)
{
case 'imperial':
if (*initial == 'inch' && *final == 'feet')
success = conv_inch2feet(unit);
default:
success = 1;
};
return success;
}
/*convertlib.h*/
#define FOOT 12 /* # of inches in a foot
int conv_inch2feet(int inch);
int convert(int unit, const char *,const char *,const char *);
/*convertlib.c*/
int conv_inch2feet(int inch)
{
feet = inch / FOOT;
return feet;
}