423,350 Members | 2,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,350 IT Pros & Developers. It's quick & easy.

Error: identifier or '(' before '{' token

P: 2
Q: Error: identifier or '(' before '{' token

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. float convertToEuro(float sek);
  5.  
  6. int main()
  7.  
  8. {
  9.    float sek, euro, result;
  10.    printf("Mata in antal svenska kronor: \n");
  11.    scanf("%f", &sek);
  12.    result = convertToEuro(sek);
  13.    printf("%.2f kronor motsvarar %.2f Euro", sek, result);
  14.    return 0;
  15. }
  16.  
  17.    float convertToEuro(float sek);
  18. {
  19.     float euro = sek * 0.095;
  20.     return euro;
  21. }
Aug 19 '18 #1

✓ answered by dev7060

You have put a semicolon just before the definition of function body which literally means the function has no body.

That is required only in the declaration of function as it tells the compiler the function name, return type and the no. and types of arguments.
Expand|Select|Wrap|Line Numbers
  1. # Preprocessor directives
  2.  
  3. //Function declaration
  4. return-type name(number and types of arguments);
  5.  
  6. main(){
  7.  body of main
  8. }
  9.  
  10. //function definition
  11. return-type name (arguments details){
  12. function body
  13. }
However if the function is defined before the main function, there is no need of declaration.

Share this Question
Share on Google+
1 Reply


P: 27
You have put a semicolon just before the definition of function body which literally means the function has no body.

That is required only in the declaration of function as it tells the compiler the function name, return type and the no. and types of arguments.
Expand|Select|Wrap|Line Numbers
  1. # Preprocessor directives
  2.  
  3. //Function declaration
  4. return-type name(number and types of arguments);
  5.  
  6. main(){
  7.  body of main
  8. }
  9.  
  10. //function definition
  11. return-type name (arguments details){
  12. function body
  13. }
However if the function is defined before the main function, there is no need of declaration.
Aug 19 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.