| | |
converting a char array to a single char
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
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.
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.
>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.
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.
![]() |
Similar Threads
- Converting specified elements of array of char (C++)
- Simple char array question (C)
- Read in a file and store in char array (C)
- adding data into an char array (C++)
- two-dimensional char array (Java)
Other Threads in the C Forum
- Previous Thread: Output to RTF
- Next Thread: pointer problems
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks binarysearch calculate changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fflush fgets file fork forloop framework function getlasterror givemetehcodez grade gtkwinlinux hacking hardware histogram inches include incrementoperators input intmain() iso kernel keyboard km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






