C array of structs 🏫

preview_player
Показать описание
C array of structs tutorial example explained

#C #struct #array
Рекомендации по теме
Комментарии
Автор

#include <stdio.h>
#include <string.h>

struct Student
{
char name[12];
float gpa;
};

int main()
{
struct Student student1 = {"Spongebob", 3.0};
struct Student student2 = {"Patrick", 2.5};
struct Student student3 = {"Sandy", 4.0};
struct Student student4 = {"Squidward", 2.0};

struct Student students[] = {student1, student2, student3, student4};

for(int i = 0; i < i++)
{
printf("name:%-12s\t", students[i].name);
printf("gpa: %.2f\n", students[i].gpa);
}

return 0;
}

BroCodez
Автор

First explanation where someone tells how to get of legth of an Array which is not simple type
Thanks man

judymofficialchannel
Автор

squidward's gpa should be higher than patrick's at least lol

silverevoker
Автор

You saved my @$$. My professor is a windbag that talks a and says nothing. You explained it in this video so quickly, I have my framework built. Love you man. fr.

jblack
Автор

Alright, here's the code I made using an array of structs:

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

typedef struct{
char speciesName[40];
int legs;
bool endangered;
} animal;

int main(){
animal spider = {"Spider", 8, false}; // I'm just making assumptions with the endangered variable, I didn't do any research on this.
animal panda = {"panda", 4, false};
animal human = {"human", 2, false};
animal flamingo = {"flamingo", 2, false};
animal animals[] = {spider, panda, human, flamingo};
int arraySize =
printf("My favorite animals are the ");
for(int i = 0; i < arraySize; i++){
printf("%s", animals[i].speciesName);
if(i != arraySize - 1){
printf(", ");
}
else{
printf(".");
}
if(i == arraySize - 2){
printf("and ");
}
}

}

PSIwolf
Автор

I don't understand why you would need to divide the sizeof(students) by sizeof(student[0])

chrisolo
Автор

I like the " sandy is smart" . makes me subscribe

mosensingle
Автор

Will placing those student structs inside the array copy the addresses of the structs or will it create new ones in memory?

Joao-ooyj
Автор

Yo Bro! Can you make some video about typedef with struct?

provokator-provocateur
Автор

Why not use typedef like you did before??

negriu
Автор

Squidward 2.0 GPA when Patrick has 2.5? Cmon man why u gotta do Squidward like that...

Acid_Burn
Автор

Weiß jemand wie man den GPA der Students absteigend geordnet anzeigen lassen kann?

leonardd
Автор

damn patrick gpa higher than squidward, why you dissing squidward like that bro

popman-my