Click here to Skip to main content
15,917,062 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: what function will convert a char to its number value Pin
John M. Drescher11-Jul-03 7:59
John M. Drescher11-Jul-03 7:59 
AnswerRe: what function will convert a char to its number value Pin
Shay Harel11-Jul-03 7:45
Shay Harel11-Jul-03 7:45 
GeneralRe: what function will convert a char to its number value Pin
johnstonsk11-Jul-03 7:54
johnstonsk11-Jul-03 7:54 
GeneralRe: what function will convert a char to its number value Pin
John M. Drescher11-Jul-03 7:56
John M. Drescher11-Jul-03 7:56 
GeneralRe: what function will convert a char to its number value Pin
johnstonsk11-Jul-03 7:59
johnstonsk11-Jul-03 7:59 
GeneralRe: what function will convert a char to its number value Pin
John M. Drescher11-Jul-03 8:02
John M. Drescher11-Jul-03 8:02 
AnswerRe: what function will convert a char to its number value Pin
John R. Shaw11-Jul-03 9:21
John R. Shaw11-Jul-03 9:21 
AnswerRe: what function will convert a char to its number value Pin
Terry O'Nolley11-Jul-03 9:27
Terry O'Nolley11-Jul-03 9:27 
I know I am asking why you are doing something rather than just answering your question so I apologize.

First, there is a way to get the numeric value of a char. Just cast the char as an int and there you go.
Second, there is no numeric value of a string so you can't do what you are asking.

In your sample code, you show:

char Names[50]

for(int i=0; i<50; i++)
{
int temp = (int)Names[i]; // reinitialization error?

if(temp = the number value of 'pla')
then do some stuff;

if(temp = the number value of 'oct'0)
then do some more stuff;
}

Where is your switch statement?
Are you simulating the switch with the if statements?

In the sample shown, you have a single name which can be up to 50 chars long. You are merely comparing 1 letter from that same name at a time. If you need 50 names, you'll need to define a 2 dimensional array like char Names[50][30];


If you absolutely have to use a switch statement (like a school project) you can create a struct which contains a key value and when you populate the struct you can increment the key.

struct NameStruct
{
char Names[50][30];
int key;
};

Then you can use the NameStruct.key value in your switch statement and access the names with NameStruct.Names[key]


If your end goal is to be able to loop through an array of strings and take a different action for each string you could try:


char Names[50][MAX_NAME_LENGTH];
int x;

for (x = 0; x < MAX_NAME_LENGTH; x++)
{
if(!strcmp(Names[x], "Text to compare"))
DoSomething();
if(!strcmp(Names[x], "Other text to compare"))
DoSomethingElse();
........
if(!strcmp(Names[x], "Last text to compare"))
DoSomethingEtirelyDifferent();
}
GeneralRe: Whoops Pin
John R. Shaw11-Jul-03 10:15
John R. Shaw11-Jul-03 10:15 
GeneralRe: Whoops Pin
Terry O'Nolley12-Jul-03 3:58
Terry O'Nolley12-Jul-03 3:58 
GeneralRe: what function will convert a char to its number value Pin
johnstonsk11-Jul-03 10:26
johnstonsk11-Jul-03 10:26 
GeneralRe: what function will convert a char to its number value Pin
John R. Shaw14-Jul-03 7:23
John R. Shaw14-Jul-03 7:23 
AnswerRe: what function will convert a char to its number value Pin
Mike Dimmick11-Jul-03 9:47
Mike Dimmick11-Jul-03 9:47 
GeneralRe: what function will convert a char to its number value Pin
Daniel Turini11-Jul-03 10:15
Daniel Turini11-Jul-03 10:15 
GeneralRe: what function will convert a char to its number value Pin
Mike Dimmick11-Jul-03 12:19
Mike Dimmick11-Jul-03 12:19 
GeneralRe: what function will convert a char to its number value Pin
Daniel Turini11-Jul-03 23:48
Daniel Turini11-Jul-03 23:48 
GeneralRe: what function will convert a char to its number value Pin
Mike Dimmick12-Jul-03 1:16
Mike Dimmick12-Jul-03 1:16 
AnswerRe: what function will convert a char to its number value Pin
drabudawood13-Jul-03 20:12
drabudawood13-Jul-03 20:12 
QuestionWhy is the constructor protected ? Pin
Shay Harel11-Jul-03 7:25
Shay Harel11-Jul-03 7:25 
AnswerRe: Why is the constructor protected ? Pin
John M. Drescher11-Jul-03 7:40
John M. Drescher11-Jul-03 7:40 
GeneralRe: Why is the constructor protected ? Pin
Shay Harel11-Jul-03 7:43
Shay Harel11-Jul-03 7:43 
GeneralRe: Why is the constructor protected ? Pin
John M. Drescher11-Jul-03 7:50
John M. Drescher11-Jul-03 7:50 
GeneralRe: Why is the constructor protected ? Pin
Shay Harel11-Jul-03 7:52
Shay Harel11-Jul-03 7:52 
GeneralRe: Why is the constructor protected ? Pin
John M. Drescher11-Jul-03 7:55
John M. Drescher11-Jul-03 7:55 
GeneralRe: Why is the constructor protected ? Pin
Anthony_Yio15-Jul-03 1:27
Anthony_Yio15-Jul-03 1:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.