Assistance, MEDIC

Intro kid going Advanced before his time :)

Page 1 of 1

10 Replies - 1311 Views - Last Post: 03 November 2001 - 09:43 AM Rate Topic: -----

#1 VxJasonxV  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 201
  • Joined: 03-October 01

Assistance, MEDIC

Posted 30 October 2001 - 06:52 PM

Well..all of Hanosh's advanced kids can now laugh at me...but hopefully you can help me too.
We learned obviously how to open an array.
ans[5]
And we just learned to open a multi-dimensional array.
ans[3][5]
But can anyone tell me if you can open up an array so you have multiple slots, but not an array length.  Like:
ans[a1][a2]
a1 is the arraySlots, a2 is the length (you can store multiple different strings...you get it I hope.)  Is there anyway I can have a1 without having a2?

(Edited by VxJasonxV at 12:00 am on Nov. 3, 2001)


Is This A Good Question/Topic? 0
  • +

Replies To: Assistance, MEDIC

#2 runtime error  Icon User is offline

  • Lucky.Code
  • member icon

Reputation: 3
  • View blog
  • Posts: 629
  • Joined: 19-March 01

Re: Assistance, MEDIC

Posted 30 October 2001 - 10:18 PM

well unless you want to get into some major memory allocation crap and pointers. there isn't a way to declare an array with out a size appointed to it.

if that is what you are asking.

Was This Post Helpful? 0
  • +
  • -

#3 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: Assistance, MEDIC

Posted 31 October 2001 - 08:26 AM

I'm not sure I completely understand what you're saying. You can declare arrays in this way:
int v[] = { 1, 2, 3, 4 };


I'm pretty sure you can do something similar with multidimensional arrays, but I never do, so I can't remember.

If this doesn't answer your question, try this:
You might be asking if you can have an array where one of the dimensions is not fixed. For example, in an array ans, ans[0] has length 5, ans[1] has length 10, etc.
If that's your question, then the answer is no. And yes.
You can't define the array so it conceptually looks that way:

OO
OO
OO
OO
OO
 O
 O
 O
 O
 O


However, you can have an array that holds strings of differing lengths. Remember that strings in C++ are null-terminated - they all end with the character '' (same as the integer 0). So you could define your array as:
char ans[2][11];


And it would be able to hold both the 5 length string and the 10 length. In the case of the 5 char length string, the 6th spot in the array would be the null terminator, and the remaining 5 wouldn't matter. In the case of the 10 char length string, the 11th spot would be the null terminator.

Hope that answers your question.

Was This Post Helpful? 0
  • +
  • -

#4 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: Assistance, MEDIC

Posted 31 October 2001 - 09:10 AM

well, you cant declare an array with a variable, but you can use a variable in those slots later. works great in for loops.
Was This Post Helpful? 0
  • +
  • -

#5 Null and Void  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 29-April 01

Re: Assistance, MEDIC

Posted 31 October 2001 - 01:49 PM

Quote

Quote: from supersloth on 11:10 am on Oct. 31, 2001
well, you cant declare an array with a variable...

The somewhat new C99 standard allows for declaring an auto array with a variable. That's NOT allowed in C++ though, it is one of the few ways that C has diverged.
Was This Post Helpful? 0
  • +
  • -

#6 VxJasonxV  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 201
  • Joined: 03-October 01

Re: Assistance, MEDIC

Posted 31 October 2001 - 03:15 PM

Quote

Quote: from malkiri on 8:26 am on Oct. 31, 2001
I'm not sure I completely understand what you're saying. You can declare arrays in this way:
int v[] = { 1, 2, 3, 4 };

I'm pretty sure you can do something similar with multidimensional arrays, but I never do, so I can't remember.

^ I think that is what I need to do...maybe.  I yes, the problem is is that you can't put a size on int's or anyother number operators.  I want to open up just slots without sizes...and I think the above is correct.

I'll try that out and get back to you.

Was This Post Helpful? 0
  • +
  • -

#7 VxJasonxV  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 201
  • Joined: 03-October 01

Re: Assistance, MEDIC

Posted 01 November 2001 - 08:38 PM

Ok, thanks people for aiding me in learning strlen, toupper, tolower, and for trying to help me with this topic...I'm getting a lot of errors that I want to figure out on my own.  So, I'll talk to you guys at the end of this weekend if I'm still stuck.
Was This Post Helpful? 0
  • +
  • -

#8 VxJasonxV  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 201
  • Joined: 03-October 01

Re: Assistance, MEDIC

Posted 03 November 2001 - 12:25 AM

float iname[]={0,1,2,3,4}, sssn[]={0,1,2,3,4}, hour[]={0,1,2,3,4}, wage[]={0,1,2,3,4}, stax[]={0,1,2,3,4}, ftax[]={0,1,2,3,4};
list >> iname;
list >> sssn;
list >> hour;
list >> wage;
list >> stax;
list >> ftax;
C:C++ADV CS PRGM 1checks.cpp(60) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'float [5]' (or there is no acceptable conversion) (this is an error for every list >> line.)
If I add iname[i] it gives me an error of 'Subscript is not of integral type.'
I keep getting these error and I don't know why.  I get even more if I put a multi-dimensional char array in.  I'll try and fix those later, but why am I getting these two errors?
Was This Post Helpful? 0
  • +
  • -

#9 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: Assistance, MEDIC

Posted 03 November 2001 - 01:36 AM

i believe it needs to be:
float iname[]={0,1,2,3,4}, sssn[]={0,1,2,3,4}, hour[]={0,1,2,3,4}, wage[]={0,1,2,3,4}, stax[]={0,1,2,3,4}, ftax[]={0,1,2,3,4};
list >> iname[1];
list >> iname[2];
list >> iname[3];


and uh, as a side note, your not going into advanced, your doing one advanced program, just thought id let you realize that, before your ego got too big ;)

Was This Post Helpful? 0
  • +
  • -

#10 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: Assistance, MEDIC

Posted 03 November 2001 - 08:12 AM

"Subscript must be integral type" means that the subscript must be an integer -- not a real number (float).
Was This Post Helpful? 0
  • +
  • -

#11 VxJasonxV  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 201
  • Joined: 03-October 01

Re: Assistance, MEDIC

Posted 03 November 2001 - 09:43 AM

"Intro kid going Advanced before his time :)"
Let's see, I said 'going advanced', and that means that I'm doing something advanced...not that I'm going INTO advanced, or anything else like that.  And I didn't say permanently either.  Even though I'll be in advanced next year.

Malkiri: Well...that makes sense.  I think I screwed something up when I had my varibles set to int...so I guess I'll try and do that now.

And I'll post again probably around 5 after I experiment with char variable arrays.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1