In a c program, you are not allowed to declare a variable in the middle of
a function. You only can do that in c++ code.
In c, you have to declare it in the beginning of the function.
So your code should be :
int main()
{
int k;
printf ...
...
k=4;
printf("k=%d\n",k);
}
I think it should work this way, and k won't be global.
HTH
Flupke
On Mon, 1 May 2000, Nickolay Belostotsky wrote:
> Hi all! This is my program:
>
> test1.c:
> int main()
> {
> printf("Hello, world!\n");
> printf("Input1=%c",getchar());
> printf("Input2=%c",getchar());
> int k=4;
> printf("k=%i\n",k);
> }
>
> When I gcc test1.c I get this:
>
> gcc output:
> test1.c: In function `main':
> test1.c:6 parse error before `int'
> test1.c:7: `k' undeclared (first use in this function)
> blah blah
>
> When I modify the program thus:
>
> test1.c:
> int k;
>
> int main()
> {
> printf("Hello, world!\n");
> printf("Input1=%c",getchar());
> printf("Input2=%c",getchar());
> k=4;
> printf("k=%i\n",k);
> }
> everything goes without a problem. But thus the integer `k' is global,
> which I don't want it to be! Is there something to be done to amend
> this? Where can I find info on Linux C?
>
> Thanks,
> -- Koly
>
>