?

Log in

No account? Create an account

The Toybox

people for the conservation of limited amounts of indignation


Previous Entry Share Next Entry
hmm
children of dune - leto 1
seperis
Started work on functions and arrays these last two weeks. Question.

Strings = a complex array?

A lot of class now is spent less with notes and more with short, simple programs as illustration, which I cannot emphasize enough how awesome that it, though it does reinforce my inability to do a damned flowchart or IPO. Anyway. I was looking at strings, since they have their very own include to be added as a data type--was that written so that there wouldn't necessarily be arrays for stuff like entire paragraphs? And how are those created?

I'm curious. I've been playing with functions a lot to see how they shorten a program, and the arrays feel very--interesting, yes, but also interestingly *useful*. Though I'm not sure how yet.

Seriously, I only have two weeks left, and I'm already missing this class a lot. I really wish they had a Christmas short semester.

Sadly, we are skipping two dimensional arrays. It is depressing.

You know, eventually, I have got to think of something more interesting to say.


  • 1
Arrays. I have bad memories of my time with them (and Java in general). But they could be useful...

2D Arrays are sort of like an array within an array. I think strings were slightly different to a complex array. But I'm pretty sure all the knowledge I had of Java evaporated after my exam, so I cant be certain!

*looks at book* That's still, so far, a better explanation than the book on teh subject. Hmm.

Strings are represented differently in different languages -- in ordinary C, any string (no matter how long) is just an array of characters terminated with the null character '\0', which leads to lots of awesomeness especially when you forget to terminate properly. In most modern languages, strings are either a class or a built-in type all their own, so the internal implementation is hidden from you most of the time, and you don't have to think of it as anything other than a string. :)

AHAHA THAT NULL CHAR. i have had so much hilarity when i forgot to add that stupid thing on at the end.

*twitch* stupid '\n'. that has caused many sad moments

Warning: geek-out ahead

Strings = a complex array?

Depends on the language, and if it's involved, the database. And the two may not deal with strings the same way. Afaik, these are the ways a string can be stored:

- an array (either exposed to the developer or not).
- a fixed length piece of data that consists of one character after another.
- a piece of data of length n that begins with a character count.
- a piece of data of unspecified length that begins with a special start character and ends with a special end character.

And depending on the language, the array may be stored in any of the last three ways, or as a linked list. (But I don't think they teach linked lists anymore.)

It doesn't hurt to think of them as arrays, most languages allow you to work with the characters as if the string was an array.

Re: Warning: geek-out ahead

C++. I was thinking about it since I was trying to get my professor to explain how to change strings so if they didn't capitalize the frist word the program would, and he was like, wait for arrays!

This does conveniently explain why soem programs have character limits when entering names. I think.

By the end of your post I had the vague feeling you might maybe perhaps be talking about computer programming (as opposed to my original thought that it was string theory therefore physics that you were going on about). The two previous comments make me think it IS computer programming. To say I'm illiterate in computer languages is really to make it sound as if I could somehow BECOME literate, if I tried. That is SO not the case. Nevertheless, I stand in awe of computer fluent people (heck, I stand in awe of the telephone, cordless or otherwise - I still haven't "gotten over" Atlantis-sized awe of pretty much any kind of machinery (how the heck does it WORK, for crying out loud!). Computers are next to God to me - incomprehensible wondrous "beings" for which my gratitude is boundless and about which my ignorance cannot be conveyed. I'm not exaggerating, truly. Anyway, those who "get" computers on any level beyond read, write, save, print, automatically earn my reverence and gratitude: without them, my life would be so much poorer, the wheel fades into insignificance in comparison.... Hope you find more ways to feed your mind on this subject, other classes, other books and teachers. We need your expertise but more, we need your love for learning.

*g* It is deeply, deeply fun.

Strings in C/C++ are arrays, which are a higher level form of stack. Strings are arrays of characters that terminate in a /0 null operator. Characters are, of course, just ASCII numerical values 0-256, I believe. Upper and lower case characters are set numerical values separate from each other.

http://en.wikipedia.org/wiki/C_string

That's what I suspected when strings are treated as singular units like numbers and not as individual characters, esp with the transform command able to capitalize or lowercase all or none.

Fascinating. *mulls*

glad you like arrays, you're going to use them a lot, most likely.

Stacks are a lower level form of array that don't have the niceties built in.

(Deleted comment)

Re: Why oh why are there different data types?

*g* I get *ridiculously* excited about it. I just love this class. I ove how its organized and writing out what I learn so it clicks and just--gah. Happy.

(Deleted comment)

Re: Why oh why are there different data types?

Do you know the programming language brainfuck? So much fun, so little use :)

Strings = a complex array?

I see in the comments you seem to be conflicting answers. Are you talking about regular strings or C-strings? Because in the case of c-strings this is definitely the case as c-strings are character arrays. However, on the regular data type string I am not so sure as to how they are actually allocated in memory, but my instinct is to say no that strings are probably a class.

was that written so that there wouldn't necessarily be arrays for stuff like entire paragraphs? And how are those created?

I don't know but that is a very interesting question. I am assuming it was written because c-strings are actually pointers* that point to a character array and therefore all normal operations(=,+,-, >, <) don't work as you would expect them to. I am assuming that what is written in the include is what fixes this to where they perform as expected.

*Have you gotten to pointers yet? They let you dynamically allocate the size of the array based of something else(user input, size, ect). So cool.

I am sure you have learned this but the first rule of arrays is: for loops are your best friend. (for(int i = 0; i > size; i++){})

(for(int i = 0; i > size; i++){}

There's a small typo :)

It should be for (int i=0; i < size; i++) {}

  • 1