Help needed in solving C-errors

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

Dan Pop

In said:
You are obviously not overly at ease with C strings. Remember: there is
no syntactic support for strings in C.

Actually there is, just not very much. String literals certainly qualify
as syntactic support for strings in C.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top