natalia.ochoa natalia.ochoa - 3 months ago 14
C Question

declaration has no storage class or type specifier

Hello: I have the following code used for counting characters:

#include <stdafx.h>
#include <stdio.h>

int main();
{
int CharCount=0; //character counter
int Text; //Text variable

Text = getchar();

while(Text != EOF);
{
CharCounter++
Text = getchar();
}
return 0;
}


in the line
Text = getchar();
the program says declaration has no storage class or type specifier. I thought it was enough to declare Texts as integer.

Can you help me please?

Answer

You have a stray ; after int main().

This causes the rest of the code to be parsed as top-level declarations, which is not valid.