Monday, May 24, 2010

How to loop a character in turbo c?

The question is unclear.





However, please beware of the following (Gopinath?!)


char c;


for (c = 0; c %26lt;= 256; ++c) ....





This is an infinite loop, as the condition c %26lt;= 256 is always true. Once c = 256 it passes the test, and then once incremented it would overflow and become c = 0 again which passes the test.

How to loop a character in turbo c?
char c;





for(c='a';c%26lt;='z';c++)


printf("%c\n",c);
Reply:not clear





but char is short int.


it occupies 1 byte and can behave like normal int. except its range is limited.





for eg.





char a;


for(a=0;a%26lt;=256;a++)


{


printf("\n %c %d",a,a);





if(a%20==0)


getch();


}


getch();


No comments:

Post a Comment