CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Can i use switch-case with characters?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Jesus_Hdez



Joined: 26 Mar 2016
Posts: 1

View user's profile Send private message

Can i use switch-case with characters?
PostPosted: Sat Mar 26, 2016 12:58 pm     Reply with quote

Hi, can someone help me please?

can i use switch function with characters?

I'm building a propeller clock, for this i want to add into my code (once i have it ) a function that receives an argument (A-Z or 0-9) and send the data through PORTB.

Example:
Code:

SYMB(C); //Where SYMB is my function or subroutine
SYMB(C);
SYMB(S);

------------------

char SYMB(){
switch SYMB
  case C:
  PORTB=XXX;
  break;

  case s:
  PORTB=XXX;
  break;
}

Or something like this Smile

Any ideas?
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Sat Mar 26, 2016 1:14 pm     Reply with quote

Almost.

Code:
void SYMB(char c) {
   switch (c):
      case 'C':
         ...do something
         break;
      case 's':
         ...do something else
         break;
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sat Mar 26, 2016 1:20 pm     Reply with quote

Code:

void symb(char val)
{ //you were saying that the function returned a character
//not that it accepted a character
   switch (val)
   {
   case 'C': //This is the character 'C'
       output_b(xxxx);
       break;
   case 's': //The character 's'
       output_b(yyyy);
       break;
   }
}


Generally in C, use the standard that ALL CAPITALS is a #define.

For the rest, get a C textbook....

I see Newguy posted while I was typing.... Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group