Thread: Why do I get this error?

  1. #1
    Registered User
    Join Date
    Aug 2009

    Question Why do I get this error?

    /* employee.c: manipulates Employees */
    #include "employee.h"
    #include <stdio.h>
    #include <string.h>
    #define MAXEMPS 10
    struct Employee{
           char last[16];
           char first[11];
           char title[5];
           int home_runs;
    static struct Employee players[MAXEMPS];
    static int numEmp=0;
    int addEmployee(void){
         if( numEmp < MAXEMPS ){
              printf("Enter last name: "); fflush(stdout);
                     return -1;
               printf("Enter first name: "); fflush(stdout);
               printf("Enter title: "); fflush(stdout);
               printf("Enter home runs: "); fflush(stdout);
               scanf("%d", &players[numEmp].home_runs);
            int index=numEmp++;
               return index;
             return -1;

    When I compile the above file I get the following error
    Can you please explain me why this is happening.Why does it say that declarations(local, int index) is not allowed.

    C:\C Language\ThinkingInC\Chapter06\functions\employee_ modularized>bcc32 lab6.c
    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    Error E2140 employee.c 30: Declaration is not allowed here in function addEmploy
    *** 1 errors in Compile ***

  2. #2
    Registered User GL.Sam's Avatar
    Join Date
    Aug 2009
    ANSI C is not like C++, where you can declare anything anywhere. Preferable declare an item at the start of function block.

    C99, hovewer, is less strict.
    The only good is knowledge and the only evil is ignorance.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Simply just return numEmp++ rather than declaring int index. Also I stongly encourage you to upgrade to VisualStudio C++, 2008 at least. It may not hurt to also include stdlib.h as well.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

Tags for this Thread