converting a char array to a single char

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

converting a char array to a single char

 
0
  #1
Feb 10th, 2006
Hello guys.

I've got a query which is most likey really simple. I've got an array of char's thats :

char temp[10] = "abcd";

I'm wondering why I can't put these into char a;

since char a = 'abcde' would be legal right? Or can a single char only hold 1 char?

Since an int can hold 123456789. and so can the int array.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 1
Reputation: eerok is an unknown quantity at this point 
Solved Threads: 0
eerok eerok is offline Offline
Newbie Poster

Re: converting a char array to a single char

 
0
  #2
Feb 10th, 2006
can a single char only hold 1 char?
Yes.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,751
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: converting a char array to a single char

 
0
  #3
Feb 10th, 2006
>char a = 'abcde' would be legal right?
If the implementation allows a character literal like that then it's perfectly legal. However, the result is not the same as an array consisting of the characters 'a','b','c', and 'd' in any case.

>Or can a single char only hold 1 char?
Obviously, a single char can only hold a single char value. Anything else is just silly.

>Since an int can hold 123456789.
Maybe, maybe not. A 16-bit int can't hold that value, but a 32-bit int can.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC