This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: microblaze getchar() not functioning properly
Hi Andrew,
Thanks for you reply. I am sorry I forgot to add j++ while posting.
It was included in my code.
Thanks,
Nagaraju
On Wed, Jul 27, 2011 at 5:22 PM, Andrew Bennett
<Andrew.Bennett@imgtec.com> wrote:
>
>> 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
>
>