Re: microblaze getchar() not functioning properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> 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
>
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux