July 19th, 2003, 08:54 PM
I can't seem to get this to work:
printf("Enter item name");
parse error before `)'
[Warning] In function `int main()':
I think it's something to do with the way I written the gets?
July 20th, 2003, 01:46 AM
I think that the problem is that gets wants to write to a string but instead it is given a struct. I think if you put.
or somthing to similar effect it might work.
July 20th, 2003, 01:10 PM
Re: struct prob
First, after you have declared a variable, you no longer need to include its data type when you use it. In fact, it is a syntax error to do so.
Second, you are wanting to use the field within apple, so you need to reference it instead of the struct it is in.
Third, when you do a return in main, then you have exited the program. The system call at the end is unreachable code that will never be executed.
Fourth, you are wanting to print out the name of the product as a string, not as a single character. Use %s instead of %c .
Fifth, you would probably want to add some new-lines, AKA "carriage-return-line-feeds". Insert a '\n' in the appropriate places in the format string of the printf.
Sixth, use code tags. Start a quote reply to this post to see how I used code tags on the following corrected version of your listing to retain indentation and keep the code listing readable:
printf("Enter item name: ");
printf("Item Name is %s\n",apple.item_name);
July 20th, 2003, 01:19 PM
from gets(stock_type apple);
how u are accessing item_name from apple structure
stock_type apple; wrong
apple.item_name; item_name is access from this statment
from printf("%c", stock_type apple);
u are using wrong format specifier, %c only for single character, %s is used for string.
here also stock_type apple is wrong
use this statement apple.item_name;
July 20th, 2003, 01:51 PM
July 20th, 2003, 02:24 PM
Oh - just one prob, it's not stopping at gets to let me input a name ie
"Enter item nameItem name is"
It just goes straight on. How do u let me input a name?
July 20th, 2003, 03:06 PM
It works for me. I'm running the code that I posted earlier. What does that part of your code look like?
July 20th, 2003, 04:17 PM
Um.. I don't think Bloodshed Dev likes gets very much, but I've managed to do it with scanf.
July 20th, 2003, 04:34 PM
I did use the MinGW gcc port that comes with Bloodshed's Dev-C++ and it works just fine for me.
July 23rd, 2003, 08:48 AM
I would suggest u clear the buffer. I dont remember the syntax off hand. I think the problem I have noticed when I was using Turbo C was the buffer had to be cleared each time before and character was being read. Hope this helps