| View previous topic :: View next topic |
| Author |
Message |
ManOnMoon Cheater
Reputation: 0
Joined: 17 Mar 2009 Posts: 26
|
Posted: Tue Mar 02, 2010 6:47 pm Post subject: Reading user input |
|
|
Sorry for the constant questions I ask on this forum without much contribution but it is easer for me to learn when i ask since my proff confuses me =(
Well time for my problem. We have to make a vigenere cipher except I dont know how to read the user input since we are not allowed to limit the string. When I asked him he said to read it letter by letter and copy it into a string but I dont know how to do that.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Tue Mar 02, 2010 7:05 pm Post subject: |
|
|
| getchar() ?
|
|
| Back to top |
|
 |
ManOnMoon Cheater
Reputation: 0
Joined: 17 Mar 2009 Posts: 26
|
Posted: Tue Mar 02, 2010 8:26 pm Post subject: |
|
|
| Will get char give me each char of the inputed line though? or will I need to use it for everyline
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Tue Mar 02, 2010 8:37 pm Post subject: |
|
|
| yes it gets each char. including \n
|
|
| Back to top |
|
 |
ManOnMoon Cheater
Reputation: 0
Joined: 17 Mar 2009 Posts: 26
|
Posted: Tue Mar 02, 2010 9:08 pm Post subject: |
|
|
| Oh ok awesome then I'll do that and cut off the '/n' for '/0'
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Tue Mar 02, 2010 9:37 pm Post subject: |
|
|
| well another way you can do this is to read in everything. then tokenise it with strtok()
|
|
| Back to top |
|
 |
ManOnMoon Cheater
Reputation: 0
Joined: 17 Mar 2009 Posts: 26
|
Posted: Tue Mar 02, 2010 10:24 pm Post subject: |
|
|
How exactly do I use getchar()? I have never needed to use it so I don'tknow how it would help if you could give
*edit
I should clarify
Say I have the input 'To be or not to be'
and I want to copy it into a string without using fgets
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
|
| Back to top |
|
 |
ManOnMoon Cheater
Reputation: 0
Joined: 17 Mar 2009 Posts: 26
|
Posted: Tue Mar 02, 2010 11:12 pm Post subject: |
|
|
I understand how it works but my programs specs does not ask the user to type anything its supposed to assume that they know what to type and then takes that string and enciphers it. What I want to do is copy it one bye one into a string. Based off the link you just gave me I cane up with this
except I dont know how to limit 'i' since i dont know how long the user input will be and i can't limit it
| Code: | for (i=0;/*insert when to stop*/;i++){
do {
c=getchar();
putchar (c);}
while (c != '/n')
message[i] = c;
return i;
} |
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed Mar 03, 2010 5:22 am Post subject: |
|
|
| look at that link above, and read the 'return value' part
|
|
| Back to top |
|
 |
ManOnMoon Cheater
Reputation: 0
Joined: 17 Mar 2009 Posts: 26
|
Posted: Wed Mar 03, 2010 11:26 pm Post subject: |
|
|
| Thank you so much for that link I ended up figuring it out as well as clarifying other questions I had
|
|
| Back to top |
|
 |
|