microblaze getchar() not functioning properly
Andrew Bennett
Andrew.Bennett@imgtec.com
Wed Jul 27 11:53:00 GMT 2011
> For the above program if i give input as:
> stefen
>
> Then it is printing on 's'
>
> I tried to print variable 'j' after getchar() function in code. Then
> for each character I enter 'j' value is incremented by two.
The problem is due to the fact that the j variable is not incremented in
the
while loop. Adding j++; in the while loop after the buf assignment will
solve your problem, ie:
#include<stdio.h>
int main()
{
int i,j=0;
char buf[10];
xil_printf("main\n");
while(j<6)
{
i=getchar();
buf[j]=i;
j++;
}
xil_printf("%s\n",buf);
return 0;
}
Regards,
Andrew
More information about the Gcc-help
mailing list