0

How to print ascii values from 0 to 255 in C++ ? i have seen many programs regarding this but didnt understand them ...so plz give expalnation also.

3
Contributors
3
Replies
6
Views
6 Years
Discussion Span
Last Post by shweta2008
0

This is the C forum so this is how you could do it in C

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i;
	for( i = 0; i < 256; i++ )
		printf("%c",i);
	return 0;
}

For C++ you could do this

#include <iostream>
using namespace std;

int main()
{
	for( int i = 0; i < 256; i++ )
		cout << char(i);

	return 0;
}

If you really need an explanation then maybe you should go look at http://www.asciitable.com/ since its pretty straight forward.

Edited by sfuo: n/a

0

Not all the values between 0 and 255 have printable ascii values. The only printable ascii values are between 32 (a space) and 126 (the dash - ). All the values outside that range will just print nothing, squares, or other seemingly random garbage. See this ascii chart for all the values.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.