C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2012, 06:48 AM
shokshok shokshok is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 shokshok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 36 sec
Reputation Power: 0
Enum issue

hi guys,

I'm kind of new in C programming..

I'm trying to show a letter from "enum" acording to his index.

I didn't find a way to do this ;\

maybe u can figure out how to this..
Quote:
#include <stdio.h>

int main(){
int num_1, num_2, unNegativeNum, firstNum, X, Y;
char capitalLetter, smallLetter;

/*scan 2 numbers for the divide, a capital letter and an unnegative num.*/
scanf("%d %d %c %d", &num_1, &num_2, &capitalLetter, &unNegativeNum);

/*print the divide between the 2 num's without the remainder, the reminder, and the real result.*/
printf("%d\n%d\n%.2f\n", num_1/num_2, num_1%num_2, num_1/(float)num_2);

/*print the ASCI value of the capital letter.*/
printf("%d\n", capitalLetter);

/*inserting the ASCI value of the small letter.*/
smallLetter = capitalLetter + 32;

/*print the value of the small letter of the capital letter that we got from the user.*/
printf("%c\n", smallLetter);

/*finding the first in the order number and print it out.*/
firstNum = unNegativeNum%10;
printf("%c\n", (char)firstNum);

/*deleting the first num by dividing it without reminder.*/
unNegativeNum = unNegativeNum/10;

/*finding the dozens number and putting the value in X.*/
X = unNegativeNum%10;

/*delting the dozens from the original numbers.*/
unNegativeNum = unNegativeNum/10;

/*input the hunderds value in Y*/
Y = unNegativeNum%10;

/*deleting the hunderds value from the original num'*/
unNegativeNum = unNegativeNum/10;

/*adding the thousand value into Y*/
Y += unNegativeNum%10;

/*building the dozens integer enum according to the assignment*/
enum XLetter{A,B,C,D,E,F,G,H,I,J};

/*building the 100' and the 1000' num' according to the assignment*/
enum YLetter{z,y,x,w,v,u,t,s,r,q,p,o,n,m,l,k,j,i};

enum XLetter x_value;
enum YLetter y_value;


printf("%s\n%s\n", x_value=X, y_value=Y );

return 0;
}


the problem as u can see is in the last 6 lines..

thnx..

Reply With Quote
  #2  
Old November 6th, 2012, 08:16 AM
G4143 G4143 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 G4143 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 1
Quote:
Originally Posted by shokshok
hi guys,

the problem as u can see is in the last 6 lines..

thnx..


Yeah O.K., maybe you could elaborate what the problem is.

Reply With Quote
  #3  
Old November 6th, 2012, 09:00 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,122 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 13 h 38 m
Reputation Power: 1949
Do not post your code in quote tags. Use code tags.

printf("%s\n%s\n", x_value=X, y_value=Y );
That is nearly gibberish. The results of those assignment expressions (in 23 years of C, I've never before seen anyone attempt to use an assignment expression as a printf argument) are int, which you are telling printf to interpret as strings. I'm not quite sure what exactly printf will do, but the result will be garbage. I think it might be interpreting those int values as pointers to where the strings are, in which case it goes to some random location in memory and interprets whatever data there as characters until it just happens to hit a zero byte.

enum's are basically identifiers for a sequence of integers starting with zero, unless you explicitly assign integer values to them. If you want to associate a particular string with an enum, the normal way would be to create an array of strings that you will then index with the enum. Another way might be to assign to the enum's their ASCII values and then printf an individual enum as a char (%c). I've used the former method and only just now thought of the latter.

Reply With Quote
  #4  
Old November 6th, 2012, 10:39 AM
shokshok shokshok is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 shokshok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 36 sec
Reputation Power: 0
cheers..

thank u very much!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Enum issue

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap