Hi,

I'm pretty new to C programming, so bear with me if this has a simple answer.
I have an error that seems very strange to me. The following code when run produces an error and crashes.

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

int main ()
{
	int i;
	char *str;
	
	gets(str);
	
	return 0;
}
The strange thing is that if i get rid of the
Code:
int i;
or if i put the
Code:
int i;
after the
Code:
char *str;
there is no error. Also, the
Code:
gets(str);
can be replaced by an analogous scanf function and the same error results. The same error also results when using a double, float, char etc... instead of an int.
However, when I declare str as
Code:
char str[4];
for example, there is no error.
Any ideas?

Thanks for your help.