void mi_start_curr_serv(void){
#if 0
//stmt
#endif
}
I’m getting an error as «error: expected declaration or statement at end of input» in my compiler. I could not find any error with the above function. Please help me to understand this error.
asked Jan 3, 2012 at 4:15
8
Normally that error occurs when a } was missed somewhere in the code, for example:
void mi_start_curr_serv(void){
#if 0
//stmt
#endif
would fail with this error due to the missing } at the end of the function. The code you posted doesn’t have this error, so it is likely coming from some other part of your source.
answered Jan 3, 2012 at 4:28
DRHDRH
7,75833 silver badges42 bronze badges
8
For me this problem was caused by a missing ) at the end of an if statement in a function called by the function the error was reported as from. Try scrolling up in the output to find the first error reported by the compiler. Fixing that error may fix this error.
answered Jan 28, 2015 at 21:54
You probably have syntax error.
You most likely forgot to put a } or ; somewhere above this function.
Kami Kaze
2,05914 silver badges27 bronze badges
answered Aug 2, 2016 at 7:35
2
For me it was a missing } bracket in a function called by the code where the error was reported. Was also reported on code calling the function that called the function missing the }. So can be hard to find if you do not know what you are looking for.
answered May 26, 2021 at 7:20
user3596809user3596809
411 gold badge1 silver badge6 bronze badges
Try to place a
return 0;
on the end of your code or just erase the
void
from your main function
I hope that I helped
answered Nov 5, 2016 at 22:24
For me I just noticed that it was my .h archive with a ‘{‘. Maye that can help someone =)
answered May 21, 2018 at 23:49
for anyone who tries to run a mpi program and gets the error above, deleting commends right before or after these symbols { } seem to do the trick.
I have both kali and ubuntu wsl, in kali the program runs fine but in ubuntu i had to delete the comments in order for the program to run
answered Dec 19, 2021 at 14:58
1
Home »
C programs »
C common errors programs
Here, we will learn why an error expected declaration or statement at end of input is occurred and how to fix it?
Submitted by IncludeHelp, on September 09, 2018
The main cause of this error is – missing closing curly brace (}) of the main() block.
Example:
#include <stdio.h> int main(void){ printf("Hello world"); return 0;
Output
prog.c: In function ‘main’: prog.c:5:2: error: expected declaration or statement at end of input return 0; ^~~~~~
In this program, closing brace of the main() block is missing
How to fix?
To fix this and such errors, please take care of curly braces, they are properly opened and closed.
Correct code:
#include <stdio.h> int main(void){ printf("Hello world"); return 0; }
Output
Hello world
C Common Errors Programs »
Expected Declaration or statement at end of Input
May be wrong:
1. A function or variable is not declared before it is used.
2. A parenthesis is missing somewhere.
Read More:
- C language error – [error] expected declaration or statemt at end of input— solution.
- error: expected declaration or statement at end of input
- error: a label can only be part of a statement and a declaration is not a statement (How to Fix)
- Error c2951: template declaration can only be used at the global, namespace, or class scope. Error c2598: link specification must be at the global scope
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- C language string processing error warning, c4996, sprintf, predicted, c4996, strcpy, c4996, strcat
- 【.Net Core】using declarations‘ is not available in C# 7.3. Please use language version 8.0 or greate
- error: declaration may not appear after executable statement in block
- Unity “Feature `out variable declaration’ cannot be used because it is not part of the C# 4.0” error
- Error c2137 of C language: empty character constant (Fixed)
- When C language refers to a user-defined type as a parameter, an error segmentation fault is reported
- [!] Invalid `Podfile` file: syntax error, unexpected end-of-input, expecting keyword_end.
- Solution to error [error] LD returned 1 exit status in C language
- On the coercion of C language
- raise ValueError(‘Expected input batch_size ({}) to match target batch_size ({}).‘
- C language — to solve the problem of program flashback when programming (in VS)
- The function and usage of argc and argv in C language
- No qualifying bean of type ‘javax.sql.DataSource‘ available: expected at least 1
- Explain stdin, stdout, stderr in C language
- ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 256,

- Forum
- General Programming Boards
- C Programming
- error:expected declaration or statement at end of input
-
09-20-2007
#1

Registered User
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> #include <stdlib.h> struct node{ char data[64]; struct node *next; }; struct node *firsta, *currenta, *newa; int main(void) { int k; scanf("%d", &k); struct node *head=NULL; do{ switch(k){ case 1: addnew(); break; }while(k!=0); void addnew(void) { struct node *newnode=malloc(sizeof(struct node)); if (head=NULL) firsta=newa=currenta; else { currenta=firsta; while(currenta->next!=NULL) currenta=currenta->next; currenta->next=newa; currenta=newa; } gets(currenta->data); currenta->next=NULL; }}SOLVED
Last edited by alzar; 09-20-2007 at 12:23 PM.
-
09-20-2007
#2

Kernel hacker
If you indent your code correctly, you’ll notice that you are missing two curly braces…
—
MatsCompilers 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.
-
09-20-2007
#3

and the hat of int overfl
Count the number of closing braces which your main() seems to have.
Read the FAQ on why you shouldn’t use gets()
-
09-20-2007
#4

Registered User
Originally Posted by alzar
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> #include <stdlib.h> struct node{ char data[64]; struct node *next; }; struct node *firsta, *currenta, *newa; int main(void) { int k; scanf("%d", &k); struct node *head=NULL; do{ switch(k){ case 1: addnew(); break; } }while(k!=0); return 0; } void addnew(void) { struct node *newnode=malloc(sizeof(struct node)); if (head=NULL) firsta=newa=currenta; else { currenta=firsta; while(currenta->next!=NULL) currenta=currenta->next; currenta->next=newa; currenta=newa; } gets(currenta->data); currenta->next=NULL; }This code was a part of an exercise that i have, so i forget to close switch and main.Sorry
-
09-20-2007
#5

Registered User
Code:
int main(void) { int k; scanf("%d", &k); struct node *head=NULL; do { switch(k) { case 1: addnew(); break; } } while(k!=0);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) { struct node *newnode=malloc(sizeof(struct node)); if (head=NULL) firsta=newa=currenta;= 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:
else { currenta=firsta; while(currenta->next!=NULL) currenta=currenta->next; currenta->next=newa; currenta=newa; } gets(currenta->data); currenta->next=NULL; }newa 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.
«Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods.»
-Christopher Hitchens
-
09-20-2007
#6

Registered User
@hk_mp5kpdw
i make some changes. What’s wrong?Code:
#include <stdio.h> #include <stdlib.h> struct node{ char data[64]; struct node *next; }; struct node *firsta, *currenta, *newa; void addnew(void); int main(void) { int k; firsta=NULL; do{ fflush(stdin); printf("enter a choicen"); scanf("%d", &k); switch(k){ case 1: printf("enter string"); fflush(stdin); addnew(); break;} }while(k!=0); return 0; } void addnew(void) { newa=(struct node *)malloc(sizeof(struct node)); if (firsta==NULL) firsta=currenta=newa; else { currenta=firsta; while(currenta->next!=NULL) currenta=currenta->next; currenta->next=newa; currenta=newa; } gets(currenta->data); currenta->next=NULL; }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-laptopLast edited by alzar; 09-20-2007 at 12:18 PM.
-
09-20-2007
#7

Kernel hacker
Not what you wnat to do. Check the FAQ for «How do I clear the input buffer» or some such.
—
MatsCompilers 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.
-
09-20-2007
#8

Registered User
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?
-
09-20-2007
#9

Kernel hacker
Originally Posted by alzar
No, another bit further down:
http://faq.cprogramming.com/cgi-bin/…&id=1043284392—
MatsCompilers 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.
-
09-20-2007
#10

Hurry Slowly
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 programAll problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
� David J. Wheeler
-
09-21-2007
#11

Registered User
@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 thereenter 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.
-
09-21-2007
#12

Kernel hacker
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].
—
MatsCompilers 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.
-
09-22-2007
#13

Registered User
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 indexit prints me
enter a choice
1
enter string
hello
enter a choice
1
enter string
thereenter 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> #include <stdlib.h> #include <ctype.h> #include <string.h> struct node{ char data[64]; struct node *next; }; struct node *firsta, *currenta, *newa; void addnew(void); void printall(struct node *head); void printanddelete( int i); int findlen(int j); int slen(char *p); int main(void) { int k,i,j,m; char ch; firsta=NULL; do{ printf("enter a choicen"); scanf("%d", &k); switch(k){ case 1: printf("enter stringn"); while ((ch = getchar()) != 'n' && ch != EOF); addnew(); break; case 2: printall(firsta); break; case 3: printf("enter a number"); scanf("%d", &i); printanddelete(i); break; case 4: printf("enter index to find length"); scanf("%d", &j); m=findlen(j); printf("%d", m);} }while(k!=0); return 0; } void addnew(void) { newa=(struct node *)malloc(sizeof(struct node)); if (firsta==NULL) firsta=currenta=newa; else { currenta=firsta; while(currenta->next!=NULL) currenta=currenta->next; currenta->next=newa; currenta=newa; } gets(currenta->data); currenta->next=NULL; } void printall(struct node *head) { struct node *current=head; if(head==NULL) return; while(current!=NULL) {printf(current->data); printf("n"); current=current->next; } printf("~"); } void printanddelete( int i) { int index=1; struct node *current=firsta; struct node *prev; while (current!=NULL){ if(i==index) {printf(current->data); if(current==firsta) firsta=current->next; else prev=current->next; free(current); current=prev; break;} else{ index++; current=current->next;} } } int findlen(int j) { struct node *current=firsta; int index=1; int l; while (current!=NULL){ if (j==index) return(slen(current->data)); else index++; current=current->next; } } int slen(char *p) { if (*p=='') return 0; else return(slen(++p) +1); }Last edited by alzar; 09-22-2007 at 03:21 AM.
-
09-22-2007
#14

Registered User
Popular pages
- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish
Recent additions ![]()
- How to create a shared library on Linux with GCC — December 30, 2011
- Enum classes and nullptr in C++11 — November 27, 2011
- Learn about The Hash Table — November 20, 2011
- Rvalue References and Move Semantics in C++11 — November 13, 2011
- C and C++ for Java Programmers — November 5, 2011
- A Gentle Introduction to C++ IO Streams — October 10, 2011
Similar Threads
-
Replies: 4
Last Post: 06-05-2002, 09:41 AM
-
Replies: 3
Last Post: 06-02-2002, 09:22 AM
-
Replies: 2
Last Post: 05-10-2002, 04:16 PM
-
Replies: 4
Last Post: 11-01-2001, 04:49 PM
-
Replies: 7
Last Post: 10-20-2001, 04:18 PM
The curly braces in writecharatpos don’t add up.
To find errors of that kind, paste your original code into a tool with source formatting help, and autoformat your code.
The error will become clear at first sight once formatted: The main function is not on column one, meaning the some earlier function is not correctly closed. Also, the first search result on the error message says «curly braces dont add up».
Formating your code is considered good practice. It helps you, and others who you ask about your code. I format code while typing, and regularly autoformat it too.
You might also consider a naming policy like CamelCasing or so, because WriteCharAtPos is so much better to read.
Commenting code, especially port-fiddling, is also considered good practice.
Some comment on what the delays are good for in initialization, for instance, would be nice. Also comment on what is being intented to be written to the port. You’ll thank yourself in 2 years, when you take a look at the library because you notice you have to change it one day.
Comments like _delay_ms(3); //3 are useless. Comment why, not what is done.
|
Лизаветка 1 / 1 / 0 Регистрация: 01.05.2017 Сообщений: 34 |
||||
|
1 |
||||
|
01.05.2017, 21:41. Показов 35433. Ответов 13 Метки нет (Все метки)
Посмотрите, пожалуйста. Выдает ошибку expected ‘}’ at end of input, но скобки везде попарно
__________________
0 |
|
Джоуи 1073 / 635 / 240 Регистрация: 05.05.2015 Сообщений: 3,546 Записей в блоге: 2 |
|
|
01.05.2017, 21:53 |
2 |
|
а на какой строке вылетает ошибка?
0 |
|
284 / 232 / 114 Регистрация: 07.09.2016 Сообщений: 584 |
|
|
01.05.2017, 21:57 |
3 |
|
привыкайте нормально код форматировать. черт ногу сломит в такой писанине.
0 |
|
Джоуи 1073 / 635 / 240 Регистрация: 05.05.2015 Сообщений: 3,546 Записей в блоге: 2 |
|
|
01.05.2017, 21:59 |
4 |
|
Во-первых, если операция только одна, то операторные скобки необязательны (хотя бы не запутаетесь)
0 |
|
Лизаветка 1 / 1 / 0 Регистрация: 01.05.2017 Сообщений: 34 |
||||
|
01.05.2017, 22:07 [ТС] |
5 |
|||
|
вот полный код программы, выдает ошибку в последней строке, пробовала убирать частично код программы, ошибка уходит, если только убрать строки #include «teoria.h» и #include «teoria.cpp, выходит ошибка в них
0 |
|
Джоуи 1073 / 635 / 240 Регистрация: 05.05.2015 Сообщений: 3,546 Записей в блоге: 2 |
|
|
01.05.2017, 22:11 |
6 |
|
#include «teoria.cpp» что значит #include исходный код C++? Вы подключаете и хедер teoria.h и исходник teoria.cpp
0 |
|
Джоуи 1073 / 635 / 240 Регистрация: 05.05.2015 Сообщений: 3,546 Записей в блоге: 2 |
|
|
01.05.2017, 22:12 |
7 |
|
И учитесь уже обрамлять код тегами [CPP] Миниатюры
0 |
|
1 / 1 / 0 Регистрация: 01.05.2017 Сообщений: 34 |
|
|
01.05.2017, 22:15 [ТС] |
8 |
|
спасибо, впредь буду оформлять нормально, это мои первые 15 минут на данном форуме)
0 |
|
Джоуи 1073 / 635 / 240 Регистрация: 05.05.2015 Сообщений: 3,546 Записей в блоге: 2 |
|
|
01.05.2017, 22:16 |
9 |
|
Лизаветка, ну а насчет инклюдов Вы поняли?
0 |
|
Лизаветка 1 / 1 / 0 Регистрация: 01.05.2017 Сообщений: 34 |
||||||||
|
01.05.2017, 22:20 [ТС] |
10 |
|||||||
|
нет. я подключаю и то и то, без хедера ошибка остается.
и вот teoria.h
Что нужно убрать?
0 |
|
Джоуи 1073 / 635 / 240 Регистрация: 05.05.2015 Сообщений: 3,546 Записей в блоге: 2 |
|
|
01.05.2017, 22:22 |
11 |
|
Лизаветка, вопрос остается прежним: на какой строке и в каком файле возникает ошибка? Можно скриншот скинуть, если сами не разбираетесь
0 |
|
DU3 284 / 232 / 114 Регистрация: 07.09.2016 Сообщений: 584 |
||||
|
01.05.2017, 22:24 |
12 |
|||
|
Решение нормально форматируйте не только тут на форуме, но и у себя в редакторе и такого рода проблем будет на порядок меньше.
1 |
|
Joey |
|
01.05.2017, 22:29
|
|
Не по теме: DU3, ждем
0 |
|
1 / 1 / 0 Регистрация: 01.05.2017 Сообщений: 34 |
|
|
01.05.2017, 22:35 [ТС] |
14 |
|
Спасибо за ответы) ошибка выволилась на последней строке основной программы, оказалось нет закрывабщейся скобки в файле teoria.cpp , спасибо за вопросы, буду работать над оформлением��
1 |
|
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
01.05.2017, 22:35 |
|
Помогаю со студенческими работами здесь Ошибка: Expected END but received ELSE …
interface uses Ошибка ‘Expected END but recieved’ interface Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 14 |

Сообщение было отмечено Лизаветка как решение