==========================================================================
from:
error: expected declaration or statement at end of input ?
[ to get rid of this advertisement]
We
are trying to compile this program and we keep getting the same error,
we can't find where the problem is can somenone help us please.
Thanks a lot
#include
#include
struct vino{
char nombre[30];
char tipo[15];
char nacionalidad[15];
char sabor[15];};
void leer(FILE* archivo, struct vino mibodega[7]){
int i; i=0;
while (i<7){
fscanf(archivo, "%s",mibodega[i].nombre);
fscanf(archivo, "%s",mibodega[i].tipo);
fscanf(archivo, "%s",mibodega[i].nacionalidad);
fscanf(archivo, "%s",mibodega[i].sabor);
i++;
}
int main(void){
FILE* f=fopen("vinos.txt","r");
int i,j;
struct vino mibodega[7];
leer (f,mibodega);
printf("%s", mibodega[4].sabor);
}
Thanks a lot
#include
#include
struct vino{
char nombre[30];
char tipo[15];
char nacionalidad[15];
char sabor[15];};
void leer(FILE* archivo, struct vino mibodega[7]){
int i; i=0;
while (i<7){
fscanf(archivo, "%s",mibodega[i].nombre);
fscanf(archivo, "%s",mibodega[i].tipo);
fscanf(archivo, "%s",mibodega[i].nacionalidad);
fscanf(archivo, "%s",mibodega[i].sabor);
i++;
}
int main(void){
FILE* f=fopen("vinos.txt","r");
int i,j;
struct vino mibodega[7];
leer (f,mibodega);
printf("%s", mibodega[4].sabor);
}
I believe you are missing an } before main
Quote:
Code:
#include |
Thanks a lot, we've manage to solve the problems and complete the program of the expert systems.
Thanks to all
==========================================================================
from:
![]() | # |
Registered User Join Date: Jan 2002 Location: Northern
Virginia/Washington DC Metropolitan Area
Posts: 2,933
| Code: int main(void) Code: void addnew(void) Code: else The whole function should either be returning a pointer to a new node, or setting an argument passed into the function to the newly allocated memory, or something like that. Bottom line is there's a lot wrong with this code that needs fixing.
__________________ On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. --Charles Babbage, 1792-1871 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 |
hk_mp5kpdw is offline | ![]() |
![]() | # |
Registered User Join Date: Aug 2007
Posts: 63
| @hk_mp5kpdw i make some changes. What's wrong? Code: #include enter a choice 1 enter stringenter a choice 1 enter stringenter a choice asd enter stringenter a choice 0 owner@owner-laptop Last edited by alzar; 09-20-2007 at 12:18 PM. |
alzar is offline | ![]() |
![]() | # |
Kernel hacker Join Date: Jul 2007 Location: Farncombe,
Surrey, England
Posts: 15,686
| Code: fflush(stdin); -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
matsp is offline | ![]() |
![]() | # | |
Kernel hacker Join Date: Jul 2007 Location: Farncombe,
Surrey, England
Posts: 15,686
| Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
matsp is offline | ![]() |
![]() | # |
CSharpener Join Date: Oct 2006
Posts: 5,524
| 1. you should
not cast malloc (see FAQ) 2. you HAVE TO check the return value of malloc 3. you SHOULD NOT use gets (see FAQ) 4. Why do you need currenta and newa as globals? Make the local for addnew 5. better to make *firsta local for main and pass it as a parameter to addnew (pointer to it actually to be able to modify it) 6. do not forget to free the list before you exit the program
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
vart is offline | ![]() |
![]() | # |
Registered User Join Date: Aug 2007
Posts: 63
| @matsp Thank you so much.I didn't know that fflush is so dangerous.I replace the fflush with while ((ch = getchar()) != '\n' && ch != EOF); but now i have another problem look: PHP Code:
ps:in the link you gave me the BUFSIZ where is? In stdio.h? @vart thank you.I know all of them but this not the finally code.I will make some of the changes you tell me in the end and also the addnew function must have no arguments. edit:i delete the first while and i haven't this problem,but maybe is necessary ?i don't know.In the book where i saw the code it cleans the input also before enter choice note:there is also other cases after, such as delete an element of the list or print an element Last edited by alzar; 09-21-2007 at 01:29 AM. |
alzar is offline | ![]() |
![]() | # |
Kernel hacker Join Date: Jul 2007 Location: Farncombe,
Surrey, England
Posts: 15,686
| You can't
just "flush" the input buffer if there's nothing there. You'll need to
try to get something first, then flush if you think the user input more
than you wanted. [But better make SURE that this is the case, otherwise
it will be the same problem]. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
matsp is offline | ![]() |
![]() | # |
Registered User Join Date: Aug 2007
Posts: 63
| i update my
post and still have some problems with what it prints me case 1 is to add a newnode case 2 to print the list case 3 to print one element(asks to give an index) of the list and delete it case 4 to find the length of a string that i gave his index it prints me enter a choice 1 enter string hello enter a choice 1 enter string there enter a choice you enter string so in enter choice i write "you" and then it didn't tell me again enter choice but enter string.why? the hole code(a little big) Code: #include Last edited by alzar; 09-22-2007 at 03:21 AM. |
alzar is offline | ![]() |
==========================================================================
==========================================================================
==========================================================================
==========================================================================
==========================================================================
==========================================================================