|
-
Mar 29th, 2001, 08:14 PM
#1
Thread Starter
Fanatic Member
Ok, i have a little problem.
I have a 128 sized character array
chararray[128]
and im trying to have the user input stored in the array
cin >> chararray;
but it gives me an illegal operation when the user hits enter.
Now, i havent learned pointers yet but im traying to make a constant array that dosent resize, but only stores values.
This is a basic exercise im trying to work on just to see if it works. Can anyone help me out? 
Thanks
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 29th, 2001, 08:58 PM
#2
Monday Morning Lunatic
Have you tried using cin.getline? That will make it slightly more flexible when using an array.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 29th, 2001, 09:08 PM
#3
Thread Starter
Fanatic Member
okay thanks i'm gonna go try that right now.
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 29th, 2001, 09:21 PM
#4
Thread Starter
Fanatic Member
actually, i just tried it and i still get the illegal operation.
Code:
char fractarray[128]
cin.getline(fractarray, 128, '\n');
any other suggestions?
thanks
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 29th, 2001, 09:28 PM
#5
Monday Morning Lunatic
This works fine for me:
Code:
#include <iostream.h>
void main() {
char fractarray[128];
cin.getline(fractarray, 128, '\n');
fractarray[127] = 0;
cout << fractarray << endl;
}
The main change I made was to make sure that it is always null-terminated by setting the last character to 0.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 29th, 2001, 09:49 PM
#6
Thread Starter
Fanatic Member
Ok, this is stupid. I dont understand why its not working. It will give me a illigal operation but then it will cout the output. So I dont get it. I kind of feel stupid for not knowing how to do this since it seems so simple? ... I did exactly what you did, do you think there might be something wrong with my C version?
Im using VC++ 6 btw.
If you want I can post more code on there, but since its that chunk of code which isnt working, I thought it was the only problem... everything before and after works good if i take the cin out.
Any other suggestions?
Thanks for the help!
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 29th, 2001, 10:28 PM
#7
Monday Morning Lunatic
Bizarre 
On VC++5 (no SP) it worked perfectly...I severely doubt it's a problem with VC++6, though. What code do you have that produces the illegal operation? Maybe something else has confused it somewhere.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 29th, 2001, 10:52 PM
#8
Thread Starter
Fanatic Member
Ok wierd, I went to another machine and I did the same code that you posted and it worked fine!!!
Now, I went back and I clicked on rebuild ALL and it executed fine.
So its fixed, I just dont know how?
O well, thanks for all the replies
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
Mar 29th, 2001, 11:01 PM
#9
Monday Morning Lunatic
Hmm Rebuild All does tend to fix things in many cases 
Anyway, after a few more questions I would have had to have given up anyway...my brain's totally fried (5am here 'cause I'm still working on this $"&"&$ coursework!)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|