User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Oct 2007
Posts: 11
Reputation: piscean123 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
piscean123's Avatar
piscean123 piscean123 is offline Offline
Newbie Poster

Question Problem in C program

  #1  
Nov 5th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,123
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 929
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Problem in C program

  #2  
Nov 5th, 2007
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 ("%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
Reply With Quote  
Join Date: May 2006
Posts: 2,723
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 222
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: Problem in C program

  #3  
Nov 5th, 2007
Originally Posted by piscean123 View Post
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...
Please use English. It's "here is the source code. Unless your name is Stepin Fetchit,. Thanks. And use CODE tags...

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
Reply With Quote  
Join Date: Oct 2007
Posts: 11
Reputation: piscean123 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
piscean123's Avatar
piscean123 piscean123 is offline Offline
Newbie Poster

Re: Problem in C program

  #4  
Nov 6th, 2007
while compiling it shows this type of error

"Nonportable pointer conversion"
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Problem in C program

  #5  
Nov 6th, 2007
"A" is a string.
'A' is a char.
code is a char.

Hope this helps.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,123
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 929
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Problem in C program

  #6  
Nov 6th, 2007
Originally Posted by piscean123 View Post
while compiling it shows this type of error

"Nonportable pointer conversion"


You're right -- I didn't read it hard enough. Should use single quotes, not double quotes, like this:
for(code = 'A';code <= 'Z'; code += 1)
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
Reply With Quote  
Join Date: Dec 2005
Posts: 3,602
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 22
Solved Threads: 414
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: Problem in C program

  #7  
Nov 6th, 2007
I suppose you could do this, just to see who's awake
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.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,301
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 455
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Problem in C program

  #8  
Nov 6th, 2007
>I suppose you could do this, just to see who's awake
You're a cruel, cruel man, Salem.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Oct 2007
Posts: 11
Reputation: piscean123 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
piscean123's Avatar
piscean123 piscean123 is offline Offline
Newbie Poster

Re: Problem in C program

  #9  
Nov 6th, 2007
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

void main (void)
{
	char code;
	for(code='A';code<='Z';code = code+1)
	printf("%c %d\n", code, code);
	getch();
}
Reply With Quote  
Join Date: Sep 2004
Posts: 6,301
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 455
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Problem in C program

  #10  
Nov 6th, 2007
>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, 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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 12:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC