•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 423,385 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,804 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 784 | Replies: 9 | Solved
![]() |
Peoples i have tried to make this simple progrem in C...
that will print alphabets A to Z and their equivalent ASCII code.. like this
A 65
B 66
.
.
.
Z
here is da source code...
int main (void)
{
char code;
for(code = "A";code <= "Z"; code += 1)
printf("%c, %d", code code);
getch();
}
tell me where is da problem
that will print alphabets A to Z and their equivalent ASCII code.. like this
A 65
B 66
.
.
.
Z
here is da source code...
int main (void)
{
char code;
for(code = "A";code <= "Z"; code += 1)
printf("%c, %d", code code);
getch();
}
tell me where is da problem
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,123
Reputation:
Rep Power: 38
Solved Threads: 929
what is the output of your program? The code looks ok, except I'd make code an int instead of char but that shouldn't cause any problem.
The format string needs a '\n' for line feed
The format string needs a '\n' for line feed
("%c, %d\n", Last edited by Ancient Dragon : Nov 5th, 2007 at 11:52 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
•
•
Peoples i have tried to make this simple progrem in C...
that will print alphabets A to Z and their equivalent ASCII code.. like this
A 65
B 66
.
.
.
Z
here is da source code...
int main (void)
{
char code;
for(code = "A";code <= "Z"; code += 1)
printf("%c, %d", code, code);
getch(); // ^
} Last edited by WaltP : Nov 5th, 2007 at 11:55 pm.
Age is unimportant -- except in cheese
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,123
Reputation:
Rep Power: 38
Solved Threads: 929
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
I suppose you could do this, just to see who's awake 
/runs.

for(code = *"A";code <= 0["Z"]; code += 1)
/runs.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Yes the problem is solved the mistake was the double quote AND the comma between the
code code
Thanks peoples out therir who replied
Here is the full and final program
code code
Thanks peoples out therir who replied
Here is the full and final program
void main (void)
{
char code;
for(code='A';code<='Z';code = code+1)
printf("%c %d\n", code, code);
getch();
} >Here is the full and final program
I'm going to pull out my chainsaw now.
>void main (void)
main returns int. No excuses. And when you say you'll return int, you'd better actually return a value too. 0 is a good choice.
>for(code='A';code<='Z';code = code+1)
For future reference, only the decimal digits are required to be consecutive. It's possible that there are non-alphabet characters between 'A' and 'Z' depending on the character set. Also,
>printf("%c %d\n", code, code);
You absolutely must include stdio.h if you want to use a function that takes variable arguments. If you don't, you must provide a prototype yourself. Otherwise it's undefined behavior. I suggest getting into the habit of always including the headers that you use stuff from in your programs.
>getch();
I'd recommend using getchar instead. It's standard, comes with stdio.h, and works everywhere. With getch you have to include the non-standard conio.h, and it's not likely to work in many places.
I'm going to pull out my chainsaw now.
>void main (void)
main returns int. No excuses. And when you say you'll return int, you'd better actually return a value too. 0 is a good choice.
>for(code='A';code<='Z';code = code+1)
For future reference, only the decimal digits are required to be consecutive. It's possible that there are non-alphabet characters between 'A' and 'Z' depending on the character set. Also,
code = code + 1 is pretty verbose. You can get away with ++code .>printf("%c %d\n", code, code);
You absolutely must include stdio.h if you want to use a function that takes variable arguments. If you don't, you must provide a prototype yourself. Otherwise it's undefined behavior. I suggest getting into the habit of always including the headers that you use stuff from in your programs.
>getch();
I'd recommend using getchar instead. It's standard, comes with stdio.h, and works everywhere. With getch you have to include the non-standard conio.h, and it's not likely to work in many places.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Random Number Problem For Lottery Program (Visual Basic 4 / 5 / 6)
- Problem with program involving classes (C++)
- Help with a problem with C++ program (C++)
- Problem with program (Java)
- simple program tokenizer problem (Java)
- How do you add animation to visual C++ program? (C++)
- problem with my program!! (C++)
Other Threads in the C Forum
- Previous Thread: How to get the dependancy graph from a make file
- Next Thread: Converting lowercase to capital



Linear Mode