Results 1 to 9 of 9

Thread: array input

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    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?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Talking

    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?

  4. #4

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    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?

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  6. #6

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    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?

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  8. #8

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Thumbs up

    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?

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width