C array of strings🧵

  Рет қаралды 86,221

Bro Code

Bro Code

Күн бұрын

Пікірлер: 46
@BroCodez
@BroCodez 3 жыл бұрын
#include #include int main() { char cars[][10] = {"Mustang","Corvette","Camaro"}; //cars[0] = "Tesla"; strcpy(cars[0], "Tesla"); for(int i = 0; i < sizeof(cars)/sizeof(cars[0]); i++) { printf("%s ", cars[i]); } return 0; }
@sanaolsadako3417
@sanaolsadako3417 2 жыл бұрын
How can I insert another string in that array?
@markangelcalaycay4165
@markangelcalaycay4165 Жыл бұрын
2:54 2:54 2:54 2:54 2:54
@alexiosalexiou3180
@alexiosalexiou3180 2 жыл бұрын
Thanks, simple, straight to the point, analytical.
@benoitgauthier6089
@benoitgauthier6089 11 ай бұрын
One VERY important point when using strcpy() that really should have been mentionned: The destination string should be large enough to accept the source string. Otherwise, it will overflow on other memory adresses and potentially corrupt your program
@Aymanne-io6vb
@Aymanne-io6vb 7 ай бұрын
You can also put space to occupy the string space being replaced if the string to replace another string is not large enough, not a permanent solution though: #include #include int main(){ char names[][10] = {"Hello", "Cameroon", "Doremi", "colagge"}; printf("No. of rows: %d ", sizeof(names)/sizeof(names[0] ) ) ; printf("No. of cols: %d ", sizeof(names)/sizeof(names[0] ) ) ; strcpy(names[1], "Dora " ); //Changes value of a string array. Put space to occupy the rest of the letters since the initial string is large. for(int i = 0; i < sizeof(names)/sizeof(names[0]) ; i++){ printf(" %s ", names[i]); } /* for(int i = 0; i < sizeof(names)/sizeof(names[0]); i++){ for(int j = 0; j < sizeof(names[0])/sizeof(names[0][0]); j++){ printf("%c", names[i][j]); } printf(" "); } */ return 0; }
@mohammedazzan7529
@mohammedazzan7529 3 жыл бұрын
yours was the simplest to understand thank you.
@farragoprismproductions3337
@farragoprismproductions3337 29 күн бұрын
For those who are dumb like me, the reason why he used two brackets for assigning an "array of strings" is because of *"an array of characters and the array of strings composed of those characters"* . A *string* in the _C language_ is simply *_a list of characters_* , but C prefers to associate it with the object known as an *array* , among other programming languages. So, having a list of words will usually entail creating a variable that stores two types of arrays, therefore it's important to use two brackets for what would then be a *2-dimensional array* . *_Definitions -_* *1. **_2-dimensional Array:_* [The incorporation of an array/list of elements that would intuitively involve the combination of two arrays.] *2. **_Arrays:_* [ 1.) A list of elements that can be manipulated in a coding project, assigned with *at least* a single bracket. 2.) A type of object in the C programming language.] *3. **_String:_* [A type of array that consists of characters.] *4. **_Characters:_* [ 1.) A data type in the C programming language, which represents a letter in the alphabet. 2.) A type of element that can be used in an array.] *5. **_Element:_* [A value that is stored in an array] *6. **_Bracket/Index Notation:_* [A notation that's used for indexing elements, but is used for limiting the number of possible elements within an array.]
@kevser176
@kevser176 Жыл бұрын
ı really couldnt get this topic but now everything is clear. thanks you are the best🥺
@EasyMathematics01
@EasyMathematics01 Ай бұрын
0:27 hello Bro, i am watching from Nepal. Mustang district is located in my country which is very popular for tourism and Himalayas. anyway thank u so much for your best teaching style sir. ❤❤❤
@movieyouser
@movieyouser Жыл бұрын
Sir, you are the help I needed
@marbles5590
@marbles5590 2 жыл бұрын
Thank you for this video! It can also be *cars[ ] in order to not have wastage of memory
@minari_0324
@minari_0324 2 жыл бұрын
damn you made our 30-60 min lecture into 3 mins
@sebastienroux1790
@sebastienroux1790 2 жыл бұрын
Can you replace for example "tesla" with a variable that ="tesla" ?
@TheScissorunner
@TheScissorunner 2 жыл бұрын
char sub[ ] = "tesla"; printf("sub = %s ", sub); strcpy(cars[0], sub);
@andrewdales9727
@andrewdales9727 2 жыл бұрын
Yes
@kevser176
@kevser176 Жыл бұрын
ı wish ı can like this video multiple times
@DarkDevilVaqif
@DarkDevilVaqif Жыл бұрын
10k subs in a day nice
@sumitupadhyay8699
@sumitupadhyay8699 2 жыл бұрын
Can we use use strings in 1d arrays?
@dkp8230
@dkp8230 Жыл бұрын
I'm pretty late but i think no since a string itself is an array of characters so an array of strings must be a type of 2D array
@zraie2455
@zraie2455 Жыл бұрын
A string is a 1D array of characters
@ambeikaam3609
@ambeikaam3609 4 ай бұрын
yepp for example: #include #define MAX_LEN 10 int main(void) { char lecturer_name[MAX_LEN] = {'A','n','g','e','l','a' }; char lecturer_name[MAX_LEN] = "Angela"; //this is a string char word[MAX_LEN] = {'h', 'e', 'l', 'l', 'o', '\0'}; int i = 0; while (i < MAX_LEN) { printf("%c", lecturer_name[i]); i++; } printf(" "); return 0; }
@farragoprismproductions3337
@farragoprismproductions3337 29 күн бұрын
​@@ambeikaam3609 lol You literally helped me turn this: #include int main(void) { const int NUM_PLAYERS = 8; // Number of elements int userVals[NUM_PLAYERS]; // User values int i; for (i = 0; i < NUM_PLAYERS; ++i) { printf("Enter player %d's jeresy number:", i + 1); scanf("%d", &userVals[i]); } return 0; } *into this:* #include #define NUM_PLAYERS 8 *
@kyte8131
@kyte8131 2 жыл бұрын
and how the hell do i take input from user?
@zkskakksis1514
@zkskakksis1514 Жыл бұрын
Scanf
@shouryadeepbera7114
@shouryadeepbera7114 Жыл бұрын
​@@zkskakksis1514causes problem when you take consecutive inputs using a loop.
@zkskakksis1514
@zkskakksis1514 Жыл бұрын
​@@shouryadeepbera7114what do you mean?
@shouryadeepbera7114
@shouryadeepbera7114 Жыл бұрын
@@zkskakksis1514 try taking inputs in a string array using loop, it will cause errors...which can be fixed by clearing the input buffer after each input.
@zraie2455
@zraie2455 Жыл бұрын
@@shouryadeepbera7114 #include #include #define NAME_LIST_SIZE 10 #define MAX_STR_LEN 21 int main() { char name_list[NAME_LIST_SIZE][MAX_STR_LEN]; printf("Please enter a name: "); char user_input[MAX_STR_LEN]; int i = 0; while(i < NAME_LIST_SIZE && fgets(user_input, MAX_STR_LEN, stdin) != NULL) { strncpy(name_list[i], user_input, strlen(user_input) - 1); printf("%s ", name_list[i]); i++; printf("Please enter a name: "); } printf(" Program finish ^_^"); return 0; } It's better to use fgets in that case
@moaz_king_1001
@moaz_king_1001 Жыл бұрын
thanks for help :)
@bernardev3
@bernardev3 2 жыл бұрын
THANKS BRO!!!!
@arkabrian5796
@arkabrian5796 3 жыл бұрын
THANK YOU SO MUCH!!!
@TheLivingCrittles
@TheLivingCrittles 6 ай бұрын
I dont understand the math for the for loop... sizeof(cars) would be 2, since 0 counts as an index. sizeof(cars[0]) is Tesla, which is 5 characters... so wouldn't you be comparing 0, 1, and 2 against 2/5 which is 0.4? so shouldn't the loop break after the first element? so confused...
@umutaydn6184
@umutaydn6184 Жыл бұрын
thanks alot!
@potatopoo6978
@potatopoo6978 3 жыл бұрын
Why is mustang not printed?
@MRCN49
@MRCN49 2 жыл бұрын
we changed it to "Tesla" a line below
@roronoazoro5672
@roronoazoro5672 2 ай бұрын
can someone tell why did it not print mustang?
@Wintre_Hesmith
@Wintre_Hesmith 2 ай бұрын
The 9th line of code, strcpy replaced the first string element "Mustang" with "Tesla" instead
@roronoazoro5672
@roronoazoro5672 2 ай бұрын
@@Wintre_Hesmith alr thanks bud
@stonedcodingtom9097
@stonedcodingtom9097 2 жыл бұрын
Thx Bro
@vlastimirzdravkovic7624
@vlastimirzdravkovic7624 2 жыл бұрын
I fucking love you
@latesttrailers-yb8pr
@latesttrailers-yb8pr Жыл бұрын
Mine ain't working
@MostaphaQamar
@MostaphaQamar Жыл бұрын
dark theme sucks. view is not clear. use light color
@Artameful
@Artameful Жыл бұрын
Thx bro
C swap values of two variables 🥤
3:53
Bro Code
Рет қаралды 29 М.
C pointers explained👉
8:04
Bro Code
Рет қаралды 207 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 553 М.
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 43 МЛН
Правильный подход к детям
00:18
Beatrise
Рет қаралды 10 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 19 МЛН
Dynamically Allocate Memory For An Array Of Strings | C Programming Example
12:10
C string functions 🔠
5:03
Bro Code
Рет қаралды 75 М.
C sort an array 💱
6:02
Bro Code
Рет қаралды 101 М.
you will never ask about pointers again after watching this video
8:03
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
2 Years Of Learning C | Prime Reacts
22:24
ThePrimeTime
Рет қаралды 319 М.
Sorting An Array Of Strings | C Programming Example
8:46
Portfolio Courses
Рет қаралды 30 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 302 М.
array vs &array Pointers Difference Explained | C Programming Tutorial
17:38
how Google writes gorgeous C++
7:40
Low Level
Рет қаралды 970 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 553 М.