Advertisements

On 2 Mar 2004 19:17:45 -0800, (spoilsport)
wrote:
>Ive got to write a multi-function program and I'm plugging in the
>functions but I keep getting this error from line 40. Im new to this
>and cant find an answer anywhere.

I guess you are...I haven't seen a compiler that doesn't give a clear,
concise message for this type of error. Here's what MSVC 7.1 says:

item_name is a "string", represented in C as an array of char or a pointer
to char (an as a function parameter, both definitions say the same thing:
that it is a pointer to char). So, picking one:

void print_item_info(const char *item_name, double item_price);

The const is to advertise that the text won't be changed as a result of
calling the function.
>
> char item_name[15], name;
> double item_price;
>
> printf ("\n\nPlease enter the name of the item: ");
> scanf ("%s", & item_name);

Don't need the & there; a naked array name used in this context is
equivalent to taking the address of its first element, so
scanf("%s", item_name);
and
scanf("%s", &item_name[0]);
are both okay (the former being easier to type and the way most folks do
it). The way you did it tends to be allowed by compilers, but I'd use just
the array name.

Now, scanf has lots of problems: you can't have white space in the item
name, if you enter too many characters it'll overrun the buffer...look
into, say, fgets and sscanf together as an alternative to using scanf.
>
> printf ("\n\nPease enter the price of the item: $");
> scanf ("%f", & item_price);
>
> top_of_page_info ();
> print_item_info (item_name, item_price); /***LINE 40***/

You apparently expect the compiler to recognize that item_name is an
array and therefore intended the first parameter to be an array of
char. It doesn't work that way. In a prototype, the names of the
parameters are irrelevant. The only thing that counts is the
parameter type. In this case, the first parameter is a char.
>
> char item_name[15], name;
> double item_price;
>
> printf ("\n\nPlease enter the name of the item: ");
> scanf ("%s", & item_name);
>
> printf ("\n\nPease enter the price of the item: $");
> scanf ("%f", & item_price);
>
> top_of_page_info ();
> print_item_info (item_name, item_price); /***LINE 40***/

Here you call the function but the first argument is an array of char.
Your compiler is correctly telling you that the first argument is
incompatible with the expected type. That is, there is no way for the
compiler to automatically convert the array to a char.

I think it is the scanf that needs the %lf, not the printf.
I didn't even catch that error in the scanf call, Jack did (good eyes,
Jack).
-leor
>
>>}
>>
>>/*************************************************************************************************/
>
>
>
><<Remove the del for email>>

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!