expected declaration or statement at end of input
时间:2010-04-17 来源:nlchjian
expected declaration or statement at end of input
==========================================================================
from: http://www.linuxquestions.org/questions/programming-9/error-expected-declaration-or-statement-at-end-of-input-621556/
error: expected declaration or statement at end of input ?
[Log in to get rid of this advertisement]
==========================================================================
from: http://www.linuxquestions.org/questions/programming-9/error-expected-declaration-or-statement-at-end-of-input-621556/
error: expected declaration or statement at end of input ?
[Log in 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<stdio.h>
#include<stdlib.h>
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
Thanks a lot
#include<stdio.h>
#include<stdlib.h>
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:
The red brace is the one you are missing. I had this error come up in a program I was working on the other day.
Thanks a lot, we've manage to solve the problems and complete the program of the expert systems.
Thanks to all
==========================================================================
from: http://cboard.cprogramming.com/c-programming/93774-error-expected-declaration-statement-end-input.html
==========================================================================
==========================================================================
==========================================================================
==========================================================================
==========================================================================
==========================================================================
Code:
#include<stdio.h> |
Thanks a lot, we've manage to solve the problems and complete the program of the expert systems.
Thanks to all
==========================================================================
from: http://cboard.cprogramming.com/c-programming/93774-error-expected-declaration-statement-end-input.html
linked list and read strings-problem
GO TO POST 6(is my new problem) { this solved I am getting this message when i am trying to compile the code series1.c:44: σφάλμα: expected declaration or statement at end of input series1.c:44: σφάλμα: expected declaration or statement at end of input where is the mistake?(maybe any missing { or })
Code:
#include <stdio.h>}SOLVED Last edited by alzar; 09-20-2007 at 12:23 PM. |
|
alzar is offline |
09-20-2007, 11:10 AM | #5 |
hk_mp5kpdw
Registered User
Join Date: Jan 2002 Location: Northern Virginia/Washington DC Metropolitan Area Posts: 2,933 |
Code:
int main(void)This is an infinite loop if k is anything other than 0. There is no modification of k beyond the initial scanf call.
Code:
void addnew(void)= is for assignment, == is to test for equality. Second, head is not in scope here. Third, currenta hasn't yet been initialized the first time the function is called, head is equal to NULL and in fact does not change it's value so it will always be NULL and the rest of the code (the else part) will never get executed.
Code:
elsenewa never gets initialized to anything valid (in the above if test it is effectively set to the same random address as currenta). Same thing with firsta and since currenta points to this random memory address I certainly wouldn't want to try and access its next pointer member. I think newa is really supposed to be newnode here in this function and firsta is maybe supposed to be set to head which gets passed in as a parameter? 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 |
09-20-2007, 12:10 PM | #6 |
alzar
Registered User
Join Date: Aug 2007 Posts: 63 |
@hk_mp5kpdw i make some changes. What's wrong?
Code:
#include <stdio.h>I am getting something like this 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 |
09-20-2007, 01:11 PM | #7 |
matsp
Kernel hacker
Join Date: Jul 2007 Location: Farncombe, Surrey, England Posts: 15,686 |
Code:
fflush(stdin);Not what you wnat to do. Check the FAQ for "How do I clear the input buffer" or some such. -- 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 |
09-20-2007, 01:18 PM | #8 |
alzar
Registered User
Join Date: Aug 2007 Posts: 63 |
i found only this http://faq.cprogramming.com/cgi-bin/...&id=1043284351 should i replace fflush with something?if yes with what? or just remove it from the code? |
alzar is offline |
09-20-2007, 01:22 PM | #9 | |
matsp
Kernel hacker
Join Date: Jul 2007 Location: Farncombe, Surrey, England Posts: 15,686 |
Quote:
http://faq.cprogramming.com/cgi-bin/...&id=1043284392 -- 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 |
09-20-2007, 09:25 PM | #10 |
vart
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 |
09-21-2007, 01:22 AM | #11 |
alzar
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:
owner@owner-laptop:~$ ./series1 /*the first time i must enter in order to print me the"enter choice"*/ enter a choice 1 enter string hello there enter a choice 0 Is there a way not to have this problem?(look in my edit down here in this post) 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 |
09-21-2007, 03:21 AM | #12 |
matsp
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 |
09-22-2007, 03:15 AM | #13 |
alzar
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 <stdio.h>Last edited by alzar; 09-22-2007 at 03:21 AM. |
alzar is offline |
09-22-2007, 12:07 PM | #14 |
alzar
Registered User
Join Date: Aug 2007 Posts: 63 |
anyone please? |
==========================================================================
==========================================================================
==========================================================================
==========================================================================
==========================================================================
==========================================================================
相关阅读 更多 +