C Programming Tutorial - 9 - I Need Arrays

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Some advice:
1. You need 1 extra byte for the null terminator, so don't forget to add 1 to whatever the number of chars+white spaces you have in your name String.
2. You will most likely need to include the preprocessor directive #include <string.h>
3. When you use strcpy, if the second string (bacon) is larger that the first string (tuna) it will give you an error because you're trying to fit 6 chars into the string that was already initialized to only 5 chars.

ShadyRapture
Автор

LOL  "your gonna sell this badboy to microsoft fior millions"

fynnkarn-wadden
Автор

easy way to remember
strcpy = string copy

alacastersoi
Автор

i had to inlclude '<string.h>' to get this to compile without errors, in case anyone was wondering.

iiigen
Автор

I just got the joke of the title... XD

"Arrays" is like saying "A raise" =P

kentronator
Автор

Add
#include <string.h>
to your header in order to get rid of the implicit declaration warning.

MrDivad
Автор

Bucky: thank you x1000 for not being that one guy who overcomplicates everything. You're a really good teacher and I have learned a ton from your videos. Keep it up man

atierintel
Автор

it will be more cooler if you could enlarge the font size

prageethchamikaraabayakoon
Автор

Always remember when using strcpy that you allocate enough bytes of memory for the buffer you are wanting to write to, otherwise you will cause your program to have a buffer overflow because the data will be forced out of bounds. For example

char tuna[13] = "I Love Tuna";
strcpy(tuna, "Tuna is the greatest food ever !!!"); <-- That right there would overflow the buffer. Always make sure and allocate enough bytes. Otherwise expect bugs and crashes

slgaming
Автор

dude, you are making good videos - and i am comparing tutorial videos usually to khan academy videos(which are generally brilliantly made by education pros). Thanks!

iikkakonola
Автор

if someone will have problem that when compiling by console on linux using gcc -o command there will be an error with "undefined reference to strcopy" you need to do 2 things :
1. change strcopy to strcpy
2. include <string.h>

karolkozakowski
Автор

Your videos are amazing!!! These are the best C Programming Tutorials Ever!

tarloktarlok
Автор

8 years later...this Playlist is still as relevant as it were 8 years ago.

rajattalnikar
Автор

This treehouse ad is starting to get very annoying.

nicholaslee
Автор

some notes i'd like to share while messing around.
In this IDE if i put

char name [6] = "Bruce"
printf(name)

Then it works just as you expect.
If i change the length of the array from 6 to 5, then it works exactly the same way.
If i leave it at a length of 6, then change the value of item 6 in the array to 'h', then it would print out "Bruceh"
If you change the 6 to 4 then it would print out "Bruc"

This makes me feel that you don't need to leave an extra byte for the terminator. At least in this IDE.

martinxXsuto
Автор

your videos are great, i never get bored. thank you!

narimancharkie
Автор

how can strcpy() work, because food was of size 5 when "tuna" was stored in it, wont copying "bacon" which is of size 6 will create a problem. memory overflow??? or strcpy() takes care of that?

mayROBO
Автор

The array size is the size of the elements of the same type but not the number of bytes because the size of a single character is not one byte.

badrchaouch
Автор

thenewboston I'm seriously surprised you didn't mention buffer overflows here. I mean they are a serious threat that I believe if you make people aware of them, they'll be less likely to occur. I obviously wouldn't expect you to explain them in detail to beginners but like I would've thought you would've said something like "If you put to many characters into a string, it causes something called a buffer overflow which is not good, so just uh don't do that. (Maybe even add: "You'll learn more on this in a later episode" or something.)

goggog
Автор

Thanks for the videos, I seem to understand C a little better now.

nanotech