[Courses] [C]Warnings? (Spoiler on Ex 7-1)
Michelle Murrain
tech at murrain.net
Wed Mar 6 22:15:03 EST 2002
Ok, so I'm blithely going along, rather far behind, now (still on chapter
7, but valiantly trying to finish chapter 9 by Friday, hah!).
I finished assignment 7-1, and I have a question. First, the code:
/*******************************************************************
* *
* An English to Metric Conversion Program *
* To convert various English units to Metric *
* *
* Usage: Enter in the number and the english unit *
* The result in metric units will be printed *
* *
*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
float value; /* the number that the user enters*/
char english[12]; /* the name of the english unit */
char metric[12]; /* the name of the metric unit*/
float result; /*the result of the calculation*/
char line[40];
int main ()
{
printf("Allowable English
Units:inches,feet,yards,miles,quarts,gallons\n\n");
while (1)
{
/* get the number and the unit from the user*/
printf("Enter in number and unit:");
fgets(line, sizeof(line),stdin);
sscanf(line, "%f %s",&value,&english);
/* figure out what english unit it is, and what to do with it*/
if (strcmp(english,"inches")==0) { /* we will convert to centimeters*/
result = value*2.54;
strcpy(metric, "centimeters");
} else if (strcmp(english,"feet")==0) { /* we will convert to meters */
result = value*.305;
strcpy(metric,"meters");
} else if (strcmp(english,"yards")==0) { /* convert to meters */
result = value*.9144;
strcpy(metric,"meters");
} else if (strcmp(english,"miles")==0) { /* convert to kilometers*/
result = value*1.61;
strcpy(metric,"kilometers");
} else if (strcmp(english,"quarts")==0) { /* convert to liters */
result = value*(3.79/4);
strcpy(metric,"liters");
} else if (strcmp(english,"gallons")==0) { /* convert to liters, too */
result = value*3.79;
strcpy(metric, "liters");
} else { /* not a valid english unit */
printf ("Sorry - not a valid english unit!\n");
continue;
}
printf("%f %s is %f %s\n",value,english,result,metric);
}
}
Now the question. I get three warnings when I compile this:
eng_to_metr.c: In function `main':
eng_to_metr.c:30: warning: char format, different type arg (arg 4)
eng_to_metr.c:34: warning: implicit declaration of function `strcmp'
eng_to_metr.c:36: warning: implicit declaration of function `strcpy'
What do these mean?
.Michelle
---------------------------------------
Michelle Murrain
tech at murrain.net
AIM/Yahoo Messenger:pearlbear0
http://www.murrain.net/ for pgp public key
More information about the Courses
mailing list