Trivial C question: iterating through chars

Niels Walet Niels.Walet at umist.ac.uk
Fri Apr 20 08:50:54 PDT 2001


Because you can't add integers to chars..
Try instead
 for (i=0; i< 128; i++)
   printf("Char %i: %c\n", i, (char)i);


Chris Richard Adams wrote:

> I'd like to view all the ASCII chars on my system.  I tried:
>
> char ch = 'NUL';
> int i;
>
> for ( i = 0; i < 500; i++)
>         printf("Char: %c/n", ch + i");
>
> This fails.
>
> 1.) What is illegal here?
>
> 2.) Can I use chars in my for look also...something like:
>
> for ( ch = 'NUL; i < 500; ch++, i++)
>
> Thanks,
> Chris
>
> _______________________________________________
> Beowulf mailing list, Beowulf at beowulf.org
> To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf

--
Dr Niels R. Walet  http://www.phy.umist.ac.uk/Theory/people/walet.html
Dept. of Physics,  UMIST,   P.O. Box 88,    Manchester,  M60 1QD,  U.K.
Phone: +44(0)161-2003693 Fax: +44(0)161-2004303 Niels.Walet at umist.ac.uk


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.beowulf.org/pipermail/beowulf/attachments/20010420/144b563f/attachment-0002.html>


More information about the Beowulf mailing list