1

I am getting the following errors:

error C2143: syntax error : missing ';' before 'type'
error C2065: 'month' : undeclared identifier
error C2065: 'day' : undeclared identifier
error C2065: 'year' : undeclared identifier
error C2065: 'month' : undeclared identifier
error C2065: 'day' : undeclared identifier
error C2065: 'year' : undeclared identifier

I am running Visual Studio.

And here is my code:

#include <stdio.h>
#include <string.h>

main()
{
    char middle;
    char first[30], last[30];
    printf("WHat us ur midint?");
    printf("\n");
    scanf(" %c", &middle);
    printf("\n");
    printf("WHat us ur name?");
    printf("\n");
    scanf(" %s %s", first, last);
    printf("ur name is %s %c %s\n\n", first, middle, last);
    printf("\n");
    int month, day, year;
    scanf(" %d/%d/%d", &month, &day, &year);
    printf("Birthdate: %d/%d/%d\n\n", month, day, year);
}

Does anyone know why these errors are happening?

mafso
  • 5,433
  • 2
  • 19
  • 40
CJR
  • 3,174
  • 6
  • 34
  • 78

2 Answers2

2

When compiling a C program, MSVC doesn't allow declarations to follow statements in a block (it uses old C90 rules - support for declarations mixed with statements was added to C in the 1999 standard).

Move the declaration of int month, day, year; to the top of your program:

char middle;
char first[30], last[30];
int month, day, year;

...
bstar55
  • 3,542
  • 3
  • 20
  • 24
  • Glad to hear it. Feel free to give one of these answers the check mark. Looks like @ouah answered 10 seconds before I did :) – bstar55 Aug 22 '14 at 23:36
  • Sorry but I had to move the check mark from your question to ouah's, since he answered first, he deserves it. Hope you understand adn thank you. – CJR Aug 22 '14 at 23:52
1

Visual Studio 2010 does not support c99 and c99 mixed declarations and statements. You have to put all your declarations (month, day, year) at the top of the main function.

ouah
  • 142,963
  • 15
  • 272
  • 331