Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Array to string
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
supaphreek




PostPosted: Wed Jun 02, 2010 11:47 am   Post subject: Array to string

What is it you are trying to achieve?
Im trying to use getchar and convert it to a string


What is the problem you are having?
idk how

Describe what you have tried to solve this problem
Tried the code below...


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


setscreen ("nocursor")

var a : char
var chars : array char of boolean
var c : array 1 .. 100 of string

for b : 1 .. 100
a := getchar
put a..
c (b) := a
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
exit
end if
end for
put ""
put c




Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
chrisbrown




PostPosted: Wed Jun 02, 2010 12:14 pm   Post subject: RE:Array to string

Although you can't "put" an array, you can use a for loop to output each character sequentially, or you can append each character to a string:
Turing:
var s : string := ""    % must be initialized
var c : char
c := getchar   % say user inputs 'x'
s += c
put s        % outputs: x
c := getchar    % user inputs y
s += c
put s      % outputs: xy
supaphreek




PostPosted: Wed Jun 02, 2010 1:44 pm   Post subject: RE:Array to string

Well, im trying to make it as a username... so i need the array to be 1 word in a string. how would i do that?

Thx alot tho, i relle appreciate ur help!
chrisbrown




PostPosted: Wed Jun 02, 2010 1:53 pm   Post subject: Re: RE:Array to string

supaphreek @ Wed Jun 02, 2010 1:44 pm wrote:
i need the array to be 1 word in a string.

I'm not sure what you mean... do you want each element in the array to contain one character? Or each element to contain one username?
supaphreek




PostPosted: Wed Jun 02, 2010 2:05 pm   Post subject: RE:Array to string

well, i need to be able to put everything in the array into 1 string....
chrisbrown




PostPosted: Wed Jun 02, 2010 2:51 pm   Post subject: RE:Array to string

Ah ok. Unless it's a requirement, you dont need the array at all, you can just append to a string using the technique in the code i provided.

If it is required, my example will still help. After all characters have been read into the array, append each character to a string using a for loop.

Again, if required: Turing will make the conversion for you but you should change c to an array of char instead of string for clarity's sake.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: