I want to know how to write a program to print all ascii values and equivalent characters using a while loop.
ascii values vary from 0 to 255.

Recommended Answers

All 23 Replies

Well, that isn't really that hard to do... :)

Here's some VB code to do it:

Dim loopvar as integer

For loopvar = 0 to 255
    Debug.print loopvar & ": " & Chr(loopvar)
Next loopvar

I want to know how to write a program to print all ascii values and equivalent characters using a while loop.

Show an attempt and folks can help with any problems you have.

ascii values vary from 0 to 255.

Actually, no, ASCII is a 7-bit code and thus has a range of 0-127. There are extensions, but implementations vary.
http://www.asciitable.com/

hey guy u follow the following coding in c :

main()

{

int i;

i=0;

do

{


printf("%d %c \n",&i,&i);


}

while(i<=255);


} /* end of prog */


Show an attempt and folks can help with any problems you have.


Actually, no, ASCII is a 7-bit code and thus has a range of 0-127. There are extensions, but implementations vary.
<url snipped>

I know Dave will be happy that someone has something to say about this post. He only needed to wait three years for a follow up response.

Horribly broken, without code tags, unindented code no less.

Apart from the broken printf call with the incorrect use of &, where is the increment to i to stop it being an infinite loop?

I want to know how to write a program to print all ascii values and equivalent characters using a while loop.
ascii values vary from 0 to 255.

Hi Smithag261,
Its very easy , yu can use following code:

#include<stdio.h>
#include<conio.h>

void main()
{
int i;
clrscr();
for(i=0; i<=255; i++)
{
printf("\n%d \t%c", i, i);
}

}

there may be printing problem with one of the character, if it happens pl add following code before the printf statement
if (i==n)
continue;

where n is the value of i when it gives an error

thanks, if yu have further problem pl do contact me at <phone number snipped>

>#include<conio.h>
Non-standard, remove the call to clrscr() and then at least your code will be portable.

>void main()
Incorrect.

Or, had you read the date on this thread, you might have realized that something that was discussed nearly 3 years ago will probably not interest anyone now. But judging by the fact that you never indented your code, used code tags, or kept contact information out of your post, I kind of doubt that you would even read that before you posted. Oh well.

Hey Dude,
TRy this Out
void main()
{
i=0;
while(i<256)
printf("\n%c",i);
}

commented: NO -2

>Hey Dude
Which dude?. The OP is married already, have 1 boy and 2 girls, and don't care about programming since he doesn' have time with all the family responsabilities.

>TRy this Out
Did you notice that your keyboard is having problems. Did you put it in the dishwasher?

>void main()
Memorize this: int main( void )

Hey Dude,
TRy this Out
void main()
{
i=0;
while(i<256)
printf("\n%c",i);
}

Why would someone want to try an infinite loop -- a program that will never end and print NULLs forever?

Hey,please try this out in TC3.0 compiler it will work Check it out

>Hey,please try this out in TC3.0 compiler it will work Check it out
Post the output. :icon_rolleyes:

Hey Aia ,

#include<stdio.h>
void main()
{
FILE *fp;
int i;
clrscr();
fp=fopen("ASCIIF.txt","w");
i=0;
while(i<256)
{
fprintf(fp,"\n%d.%c",i,i);
i++;
}
fclose(fp);
getch();
}

This is The Actual Code I have Just Given the Outline b4
The Output will be in the file ASCIIF.txt Please Create it b4 u run this program in the Same directory

> This is The Actual Code I have Just Given the Outline b4
Not it is not. The code you posted before was a loop that would never stop displaying "nada". Did you read this before?:

Why would someone want to try an infinite loop -- a program that will never end and print NULLs forever?

You really need to read how to properly tag your code. Click here

>void main()
I told you before that main returns a type int, so it can not be void.
clrscr(); and getch();
requires a header file that you are not including. And it doesn't matter if it works with TC3.0 compiler or not. That file is <conio.h>
Nevertheless, that makes the code not portable because they are not standard C functions. And in fact you don't need them here neither.
getch() can be sustitude in this case for getchar()

Oyeah,This will work in TC 3.0 Compiler Check it out n then Speak about the Code

Any way Y do U bother about the Code in Syntax Bother in its Logic

>Oyeah,This will work in TC 3.0 Compiler Check it out n then Speak about the Code
I am not saying it doesn't work in you compiler. I am tell what I see that you could improve in your code.
In this case I don't need to "Check it out" to know what it does. So I can "Speak about the Code".

>Any way Y do U bother about the Code in Syntax Bother in its Logic
I bother because it makes you a better programmer.
The logic is precarious.
For example:
Did you bother to check if the file could be writen?
>fp=fopen("ASCIIF.txt","w");
What happens if the file could not be writen?

Sorry Aia ,If I had Hurt u
I have Spoken Like That Coz U had given Me Harsh Replies 4 my Evry Reply Please Excuse Me Plzzzzzzzzzzzzz

>Sorry Aia ,If I had Hurt u
No hurt done, no need to be sorry.

>U had given Me Harsh Replies 4 my Evry Reply
No harsh replies from my part. No desire to be harsh neither. Just quick points to your code.

K Thanks Can u give me ur Mail idn ur ASL PLz

K Thanks Can u give me ur Mail idn ur ASL PLz

Sorry I don't understand what ASL means.
You can send me a private email any time that you wish. However is against the rules to ask in emails for code help on personal basis. Code questions should be addressed in the forum posts.

commented: ASL means "Another Sodding Lamer" +7

ASL Means Age,Sex,Location n give me ur Yahoo Mail id(if u have)

>ASL Means Age,Sex,Location n give me ur Yahoo Mail id(if u have)
This is something you should ask for privately.

>Any way Y do U bother about the Code in Syntax Bother in its Logic
So you enjoy being a weak programmer who writes bad code?

K Thanks Can u give me ur Mail idn ur ASL PLz

Praneeth, please read this from the site Rules.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.