You are not logged in.
121
Saw you're post on the RP, Darky, what happened?
22 Don't worry little sis. It was nothing major. A bit exhausting buuut...nothing painful or anything, lol. I don't even know why I was dragged into it.
Quoting from the RP page:
((Don't worry :) A fight erupted between friends and all of a sudden I got dragged into it. It's not thing major really and in my opinion it was very silly. I don't even remember what they were fighting about, LOL. Anyways, it lasted longer than I would have preferred and I was kinda exhausted afterwards. Silly, right?))
23
Okay cool ;)
I know how those things work ^^
22
ahh, I was worried for a bit Darky :< But it's good that nothing major happened. It's hard if ur friends fight D:
23 Yeeeah but all is well now. And it was silly silly silly :P
24
So...My teeth are dying.
I got actual braces yesterday and the expanders got off. This I guess is so so much better than expanders though.
25
Finally home after 2 months. The internet is magic here.
26 wow!!! Congrats!
27
Welcome back to good internet ^^ Were you at the camp this whole time though?
28 God this place is so deserted...i so missed Bloodsy, Malu and Amary :( :(
Girls, I don't know if you check the boards, but if you do, good luck with the new school year and we missed you!!!
29
Oh yeah
Damn. I forgot to wish everyone a happy school year. Twin, it's your last year, good luck!!
So darky...what's up?
28
@ruki - home, where your wifi connects automatically :D
and ahhh, yeah, it seems so mellowed out :< hope they can come back some day unu
Good luck with studies and stuff everyone :)
Lol wasn't it 129?
@Angel : nope I've been there only for 2 weeks at the start of August but after that I went straight to my granny's place and that is some kind of mountain area.
School starts next week so I have one more week of laziness. How old are you guys again?
29 Nothing much Angel. Same as always. All of my classes are online now. I'm taking things pretty slow so I have time for work.
ooh btw. Found out that you can get the tools needed to make an XBox game for free <3 and I'm trying to learn that. It's very very very easy so far. I need to teach myself to make sprites, though :(
oh chiz, apparently
128
@ruki: Luuucky D: School re-started (we had term break last week) just yesterday for me. I'm 16 but that's college age in my country so here I am in college :<
@darky: oooh! that's so cool! I'm learning more about Arrays and Dynamic Allocation this term. We have a "textbook" but I'm still slightly confused about things.
129 Aaaaah. For a good reason. Arrays can be easily explained if a person put their mind to it. Dynamic allocations are somewhat harder to explain...Need help? I could try to explain those.
128
Yes, please @n@ I don't need really complex stuff, just basic stuff. I'm kind of getting it but im not sure so couldya just explain best you can so I know if I understand correctly?
129 Which language are you using? So I could explain dynamic allocation?
For arrays, basically it's like this. Whenever you need a collection of things of the same type, you create an array for them. The name of the array would be the name you use to refer to the collection.
For now, we'll use an array of integers, okay?
If I have an array called arrayA and it has 5 integers, then to be able to use each individual integer in there, I have to specify which one exactly I want. The way you do it is basically you say I want the first integer. Or I want the second integer. Or so on. That order we specify is referred to as 'index'.
Most languages have those indices starting from 0. So the first element would have index 0.
So, if this is my array.
arrayA = {5,3,7,4,7}
arrayA[0] would return 5.
With me so far?
128
C language! :)
Also, yeah, I get arrays and how they work and stuff; I learned them before in Java so I needed a refresher, but I do have a question about it; what if you want someone's string input to be an array? Like I'm pretty sure there's anly char variable in C so what if you need a string from someone?
129 oh ok. Let's see. Let's start with C Strings.
True. There's only char in C. Basically Strings in C are arrays of characters.
So if I want a string for "Cat".
It would be
char catString[4];
catString[0] = 'C';
catString[1] = 'a';
catString[2] = 't';
catString[3] = 0;
Notice how we had to terminate with a 0? That's because C needs to know where the end of the String is. That's very important and many of the bugs result from it. So basically a string is an array of size (number of characters + 1).
To get a string say from the user, you use a function called scanf. For example:
char S1[MAX_STRING_LEN]; // You specify how long the string is allowed to be
scanf("%s",S1);
FYI, scanf returns a -1 if it failed to read. Otherwise it returns the number of characters it read from the user.
To get the length of string, you use strlen:
int l = strlen(S1);
Is that what you were asking?
128
ohhhh, okay so let's say I want the user to input 'stew'
so i have to have
char s1[5];
scanf("%s", s1[5]);
with this, once the program runs and the user inputs "stew" will s1[0] automatically be 's' s1[1] will be 't' and so on and so forth?
129 when you're passing it to scanf, you only pass in the name of the array so,
it should be scanf("%s",s1) not scanf("%s",s1[5]).
s1[5] is a character after all.
But yeah, that should be it.
Just remember, it's better to manually set the last character to 0 yourself or you don't know what the memory might have in there for you. believe me you do not want to go into that. So after reading from the user. Change the last character s1[4] to 0.
OH And you'll need to do add this to the top of your code to get that code to run:
#include<stdio.h>
#include<string.h>
Oh and look what I found! Some of the notes I had from when I was studying this:
Program 2: Arrays of Characters
#include<stdio.h>
#include<string.h>
#define MAX_STRING_LEN 80
int main() {
/* strings are array of characters
* terminated by the NULL character
* which is different from '0' */
char S[MAX_STRING_LEN];
int l, i;
S[0] = 'a';
S[1] = 'b';
S[2] = 'c';
S[3] = 'd';
S[4] = 'e';
S[5] = 'g';
S[6] = '0';
S[7] = 0;
l = strlen(S);
printf("S:\t%s\n",S);
printf("length:\t%d\n",l);
/* print characters in S */
printf("forward\n");
for (i = 0; i < l; ++i)
printf("A[%d] = %c\n",i,S[i]);
/* print characters in S backwards */
printf("\nbackward\n");
for (i = l-1; i >= 0; --i)
printf("A[%d] = %c\n",i,S[i]);
}
Program 3: String IO
#include<stdio.h>
#include<string.h>
#define MAX_STRING_LEN 80
int main() {
/* strings can be read using scanf with %s
* string.h contains many useful functions
* for working with strings:
* strcmp for string comparisons
* strcpy to copy strings
* ...
*
* Check what happens if your input contains
* spaces, tabs, etc
*
*/
char S1[MAX_STRING_LEN];
char S2[MAX_STRING_LEN];
int i, l;
printf("String:\t");
scanf("%s",S1);
/* we need to copy all the characters, and
* the final NULL character!
*/
l = strlen(S1);
/* rather than writing this loop
we could also write strcpy(S2,S1) */
for (i = 0; i < l+1; ++i)
S2[i] = S1[i];
/* change original S1 */
S1[0] = S1[1] = S1[2] = '*';
S1[3] = 0;
/* print both strings */
printf("S1:\t%s\n",S1);
printf("S2:\t%s\n",S2);
}
I think I had gotten that from a website somewhere.
P.S: I need to be offline for like 30 - 45 mins and then gonna come back.
Last edited by darkelfqueen (2014-09-09 16:34:17)
128
Ahhh.. right 'course. S[ <a number> ] would be a character and S would be the set of characters aka. the string.
So like if the string has 6 characters, S[0] - S[5] would be taken up by the characters and I should set S[6] to 0?
And yeah, no problem. Thanks for the help! Your notes are rlly helpful too :>
129 quick answer before logging off.
Yep. S[6] = 0. Note how I didn't do S[6]= '0'? Because the latter puts the character 0 in the string. The first one is just plain old zero meaning it's the end of the string.
AND I'm BACK!
Last edited by darkelfqueen (2014-09-09 17:25:06)
130
Wow o.o Words.
Hey darky, are you continuing with the javascript? I finished the first lesson and have constantly been checking for more :>