You're missing a type in the definition of i, and the type in the definition of str is incomplete: you say “pointer” (with the * character) but you don't say to what. For historical reasons, if you omit a type, the compiler assumes you meant int; this is deprecated, and good compilers warn about this.
Since you effectively wrote int *str, the memory layout looks something like this after entering hello (this is machine-dependent, but this is a pretty typical case):
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----
| 'h' | 0 | 0 | 0 | 'e' | 0 | 0 | 0 | 'l' | 0 | ...
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----
^ ^ ^
| | |
str str+1 str+2
Each small cell is one byte (which corresponds to one character). Four cells make up one int. The line
str[i] = c;
writes one int into str. For example, when c is 'h', which has the numerical value 104, the number 104 is written into the int object str[0], which is represented as the four-byte sequence {104, 0, 0, 0}. This happens again for the next character, which is written in the next int-sized slot in the array, meaning 4 bytes further.
In the line
printf("full str:%s\n", str);
you print str as a string. In a string, the first zero byte marks the end of the string. So you see the string "h".
Your machine is little-endian. Exercise: what would you see on a big-endian machine?
The fix is to declare the types properly.
You should also initialize your variables. static variables are initialized to 0 anyway, but it's clearer if you do it explicitly. The variable c is not static, so it starts out containing whichever value was there before in memory; this could happen to be 'X', so you must initialize it explicitly.
Additionally, you need to make sure that the string is terminated by a zero byte before printing it. The static keyword ensures that the str variable is initialized to a null pointer, but the space that the pointer points to is allocated by malloc and contains whatever was there before.
void gime_char(char c)
{
static char *str; /* <<<< */
static int i; /* <<<< */
if(i == 0)
str = malloc(sizeof(*str) * 10);
if(c == 'X')
{
str[i] = 0; /* <<<< */
printf("full str:%s\n", str);
}
printf("c == %c\n", c);
str[i] = c;
printf("d == %d\n", i);
i++;
}
int main()
{
char c = 0; /* <<<< */
while(c != 'X')
{
c = getchar();
gime_char(c);
}
return 0; /* <<<< */
}