char question
Author |
Message |
pavol
|
Posted: Sat Mar 11, 2006 4:59 pm Post subject: char question |
|
|
what does the char '\n' mean? space or enter or something else? how many characters does it represent? i am totally lost
any help would work for me  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
md

|
Posted: Sat Mar 11, 2006 5:03 pm Post subject: (No subject) |
|
|
it's a newline character; and it is indeed a single character. The \ indicated an escape sequence and the n indicates a newline character. check out \a (iirc; it's supposed to be a bell) |
|
|
|
|
 |
pavol
|
Posted: Sat Mar 11, 2006 5:15 pm Post subject: (No subject) |
|
|
ok thanks. now the reason i asked was because i'm trying to make sense of the chat program in the turing reference thing (the program is under Net.OpenConnection). the thing that bothers me is, me and my friend tried this program out, and whenever he would type something instead of me seeng the letters one after another only until the enter was pressed, in which case it would start a new line, i saw the letters spelled out vertically one letter per line. i hope i haven't confused anyone cuz i've just confused myself even more.
this is the main code where the characters are got and put:
code: |
var localRow : int := 2
var localCol : int := 1
var remoteRow : int := maxrow div 2
var remoteCol : int := 1
loop
if hasch then
input := getchar
put : stream, input
if input = '\n' then
localRow := localRow mod (maxrow div 2) + 1
localCol := 1
Text.Locate (localRow, localCol)
put ""
Text.Locate (localRow, localCol)
else
Text.Locate (localRow, localCol)
put input ..
localCol += 1
end if
end if
if Net.CharAvailable (stream) then
get : stream, input
if input = '\n' then
remoteRow := remoteRow mod (maxrow div 2) + 1 + (maxrow div 2)
remoteCol := 1
Text.Locate (remoteRow, remoteCol)
put ""
Text.Locate (remoteRow, remoteCol)
else
Text.Locate (remoteRow, remoteCol)
put input ..
remoteCol += 1
end if
end if
end loop
|
|
|
|
|
|
 |
pavol
|
Posted: Tue Mar 14, 2006 1:05 pm Post subject: (No subject) |
|
|
sorry i don't think i phrased my question too well, but i did have a question in the previous post. could anyone give me any pointers on how the fix the problem where the letters appear vertically and one by one? im very confused
thanks in advance  |
|
|
|
|
 |
MysticVegeta

|
Posted: Tue Mar 14, 2006 6:45 pm Post subject: (No subject) |
|
|
could you set it up so that we dont need the streams, cause too lazy to create all the files and put in appropriate chars in it. |
|
|
|
|
 |
pavol
|
Posted: Tue Mar 14, 2006 6:47 pm Post subject: (No subject) |
|
|
i'm lost . i'm not sure i know what you mean. how am i supposed to do that? |
|
|
|
|
 |
pavol
|
Posted: Tue Mar 14, 2006 7:03 pm Post subject: (No subject) |
|
|
actually i think i know what you mean now. except if i just have the program feed the input variable with random characters, the program works. im not sure if this is right but is there, after every char passed through Net, some kind of Enter-like thing that would make it appear as if the person was pressing enter after every letter.  |
|
|
|
|
 |
MysticVegeta

|
Posted: Tue Mar 14, 2006 7:47 pm Post subject: (No subject) |
|
|
Could you rephrase that please? I dont quite get what you are trying to do and what I meant by editing the code was that, make the code so that the characters are input-ed? by keyboard not by streams so one can find out the problem. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
pavol
|
Posted: Wed Mar 15, 2006 11:15 am Post subject: (No subject) |
|
|
ok i made the program so that it gets the chars through the keyboard instead of the stream but if i do that, my program works. it does what it's supposed to. i even tried just feeding it random chars:
code: | var input : char
var localRow : int := 2
var localCol : int := 1
var remoteRow : int := maxrow div 2
var remoteCol : int := 1
var a, b : int
cls
loop
if hasch then
input := getchar
put input
if input = '\n' then
localRow := localRow mod (maxrow div 2) + 1
localCol := 1
Text.Locate (localRow, localCol)
put ""
Text.Locate (localRow, localCol)
else
Text.Locate (localRow, localCol)
put input ..
localCol += 1
end if
end if
randint (b, 1, 500)
randint (a, 97, 122)
if b = 1 then
input := chr (a)
if input = '\n' then
remoteRow := remoteRow mod (maxrow div 2) + 1 + (maxrow div 2)
remoteCol := 1
Text.Locate (remoteRow, remoteCol)
put ""
Text.Locate (remoteRow, remoteCol)
else
Text.Locate (remoteRow, remoteCol)
put input ..
remoteCol += 1
end if
end if
delay (10)
end loop
|
but it works (a little glitchy but it does the job, i think). only if i have the original code there, with the streams and everything, it doesn't work. so, what i think is that when i get the char from the stream, there is another character that comes with it instead of the one just typed in: Enter. because when i use the program to connect to someone and chat with them when they type something, on my screen the program puts every letter on a seperate line. is there an enter at the end of every char passed to my program or is it just very messed up. i'm clueless and i hope i haven't confused you even more  |
|
|
|
|
 |
|
|