converting a char array to a single char

Reply

Join Date: Dec 2004
Posts: 490
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: 8,299
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: 819
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.
In case you were wondering, yes, I do hate you.
Reply With Quote Quick reply to this message  
Reply

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




Views: 3015 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC