Read an array of structs in C

  Рет қаралды 32,098

CodeVault

CodeVault

Күн бұрын

Пікірлер: 76
@naboulsikhalid7763
@naboulsikhalid7763 8 ай бұрын
as usual, you explained with your heart, so all you demonstrated stayed vivid in my mind. thank you
@Sword001SK
@Sword001SK 3 жыл бұрын
I am so glad that I found you. Thanks for making these C lecturing videos!
@diogenes_of_sinope
@diogenes_of_sinope 11 ай бұрын
Thank you very much for your efforts and sharing the knowledge, you are a good person and you will be rewarded for the enlightenment of people.
@akhilpandey1539
@akhilpandey1539 9 ай бұрын
Don't stop making such videos please
@tynanmcgrady2624
@tynanmcgrady2624 4 жыл бұрын
brilliant explanation , thank you!
@Jorgeee
@Jorgeee 4 жыл бұрын
Hey man, will you ever upload c++ tutorials? You explain everything so amazingly it's very easy to follow. You would make the c++ syntax so much easier to understand
@CodeVault
@CodeVault 4 жыл бұрын
Possibly, if enough people want me to. For now, I've got a lot planned for C programming tutorials and other computer science related topics which I found many people lack knowledge in.
@abdurezzaq758
@abdurezzaq758 2 жыл бұрын
Thank you for this amaizing explanation!❤
@ignabelitzky
@ignabelitzky 4 жыл бұрын
Hey man... your vids are amazing!!! You deserve more subscribers!!!
@oliverondrus1470
@oliverondrus1470 2 жыл бұрын
You just saved my ass right here , Thank youuu.
@hey-its-me239
@hey-its-me239 2 жыл бұрын
THANK YOU SO MUCH FOR SAVING MY LIFE AND PROJECT! IT WORKED YEAHHH❤
@yusefalimam130
@yusefalimam130 3 жыл бұрын
excellent presentation, ill be checking this channel out for sure!!!
@anjalibhatt56
@anjalibhatt56 4 жыл бұрын
I'll start this series once I'm done with basic... Thank you 👌
@chillydoog
@chillydoog 4 жыл бұрын
Ok. Sounds good!
@zaabimahdi
@zaabimahdi 4 жыл бұрын
@CodeVault! Hey where are you ! C community miss your videos on youtube !
@admirmehmedovic4308
@admirmehmedovic4308 2 жыл бұрын
This helped me a lot, thanks;
@relaxingweathersoundsrainy1138
@relaxingweathersoundsrainy1138 4 жыл бұрын
There are five data (plain text) files, namely, the “students.txt”, “courses.txt”, “registrations.txt”, “criteria.txt”, and “performances.txt” that keep information. Student file keeps the information about students such as the student number, name, surname, and department in abbreviated form. Course file keeps the information about courses such as the course code and course title. Criteria file keeps the information about course assessments such as the course code, course credit value, homework, lab, quiz, midterm, and final percentages. Registration file keeps the information about the student’s registrations such as the student number, academic year, semester, and course code. Performance file keeps the information about the student’s performances such as the student number, course code, and performances. The program should read all given files and should prepare transcripts for each student i am managed to read all files into structures but i am failing to match and collect information for each student @CodeVault please help
@CodeVault
@CodeVault 4 жыл бұрын
Head on over to our discord server (link in the description) and you can ask there in more details what your issue is.
@relaxingweathersoundsrainy1138
@relaxingweathersoundsrainy1138 4 жыл бұрын
@@CodeVault ok thanks man
@davidsampson94
@davidsampson94 4 жыл бұрын
love these vids please continue very good
@starfart69
@starfart69 3 жыл бұрын
Around @8:30, line 22, why would you rather use another struct pointer p instead of just using the struct in line 19 which is points[100]? From what I understand you modified the values on the same address anyway.
@CodeVault
@CodeVault 3 жыл бұрын
Doing this: Point p = points[i]; sscanf(buffer, "%d %d %d", &p->x, &p->y, &p->val); Would NOT change the array as p would simply be a copy of "points[i]". But you could use points[i] directly if you don't like that pointer. Instead of sscanf(buffer, "%d %d %d", &p->x, &p->y, &p->val); it could be done with: sscanf(buffer, "%d %d %d", &points[i]->x, &points[i]->y, &points[i]->val); The pointer was just used for shortening the code.
@starfart69
@starfart69 3 жыл бұрын
@@CodeVault thank you!
@yourlocalsuedi
@yourlocalsuedi 4 жыл бұрын
Dude you saved my mf life! Greetings from Sweden! 🇸🇪
@othmaneer-rouhly8121
@othmaneer-rouhly8121 2 жыл бұрын
Thank you so much legend
@Zahra-qb7nm
@Zahra-qb7nm 3 жыл бұрын
Hi thank you for your videos! Got a question though, in my program i’ve array of struct, struct User* user; And the elements are lets say username[200]; password[200]; But when i’m passing them to int functions, from one function to another, the data that has been saved before seems to vanish For example in a function i strcpy(user[i].username,”bluish”); and it saves successfully but when i pass it to another function it writes for that. Can tell where its problem? And in the function that im saving the username it’s like Signup(&user, i) so that it saves but in the other function it’s just (user,i) as arguements
@CodeVault
@CodeVault 3 жыл бұрын
How are you accessing that data?
@Zahra-qb7nm
@Zahra-qb7nm 3 жыл бұрын
@@CodeVault ah thank you! It got sorted, the access was also through watch window, thank you for the video it helped me alot :)))
@TehRespawner
@TehRespawner 2 жыл бұрын
thanks for the tutorial! but im having trouble understanding how the information gets stored in the variable 'points'. i dont see it being assigned other than the *p = points + i, but this is assigning p? .. sorry if my question is stupid, but im a beginner programmer so its a little bit confusing :)
@CodeVault
@CodeVault 2 жыл бұрын
It's this line that is setting things in the points array: sscanf(buffer, "%d %d %d", &p->x, &p->y, &p->val); Since *p = points + i; We know that p points to some element in the points array. Then, in that sscanf line we do: &p->x This is a two step process: p->x means "get whatever is at the address p is pointing to (which is an element in that array) and get the x member of that element" &p->x means "get the address of the result of p->x (from above)" Thus &p->x gives us an address to the x member inside of an element in that points array. Same logic for the rest of the parameters in that sscanf line
@mika1758
@mika1758 3 жыл бұрын
how can we do this for csv (excel) files
@CodeVault
@CodeVault 3 жыл бұрын
Just change the format string to output CSV: sscanf(buffer, "%d,%d,%d", &p->x, &p->y, &p->val);
@mika1758
@mika1758 3 жыл бұрын
@@CodeVault Thank you
@alexbravo7467
@alexbravo7467 3 жыл бұрын
yes, thank you, buddyboy ...
@anupkodlekere8604
@anupkodlekere8604 4 жыл бұрын
what shortcut did you use at 7:45 to select all the dots?
@CodeVault
@CodeVault 4 жыл бұрын
I pressed CTRL+D to create a new cursor at the next occurance of the same selection
@aibou2399
@aibou2399 3 жыл бұрын
@@CodeVault nice!
@MKSundaram
@MKSundaram 3 жыл бұрын
Yes, one of the best. How do I store lines from files into an array? I tried few things but failed. My file contains "test line 1 in the first line and in next line test line 2 and so on.... there is a total of four lines. One of the solutions was declaring a 2D array and store the four lines and this made me more confused, could you please help me? thanks :-)
@CodeVault
@CodeVault 3 жыл бұрын
Yea, basically a 2D array or an array of strings should be good enough. You can simply call in a while loop. char strArray[100][100]; while (fgets(strArray[i], 100, file) != NULL) { i++; } Something like this... also, make sure your file has a new line at the end so that the while loop doesn't stop prematurely.
@MKSundaram
@MKSundaram 3 жыл бұрын
@@CodeVault Thanks a lot
@afsanehakhbari8880
@afsanehakhbari8880 3 жыл бұрын
thank you for perfect explanation would you please describe how we can pass struct and struct arrays to the pthread_creat
@CodeVault
@CodeVault 3 жыл бұрын
I will make a video on that. But it's really the same way as you'd pass an integer. Usually dynamically allocated so that it doesn't get overriden: struct Example e = malloc(sizeof(struct Example)); e->x = 1; e->y = 5; pthread_create(&th, NULL, &routine, e);
@afsanehakhbari8880
@afsanehakhbari8880 3 жыл бұрын
@@CodeVault thank you so much for the answer. Is there any platform for asking questions? because the way you introduce processes and threads are perfect and easy understandable.
@CodeVault
@CodeVault 3 жыл бұрын
Yes! I answer questions regularly on our Discord server: discord.code-vault.net There will soon be a similar feature on our website as well: code-vault.net
@ib1664
@ib1664 4 жыл бұрын
How do you delete a line of data in a serialized record
@CodeVault
@CodeVault 4 жыл бұрын
The easiest and foolproof way is to just read everything into an array, delete the element and write everything back into it
@asifsaad5827
@asifsaad5827 4 жыл бұрын
same thing happens when you do that with class type?
@CodeVault
@CodeVault 4 жыл бұрын
Classes don't exist in C. But, sure, you can use the same technique with classes in C++. But you can use streams there.
@bharatnarayana8401
@bharatnarayana8401 3 жыл бұрын
{"sam","0004","SDE1","VLSI"} what will be the de serialization format i.e to read this type of forat const char* PERSON_FORMAT_IN=....?
@CodeVault
@CodeVault 3 жыл бұрын
Here you can't really use %s, but you can specify that you only want a string with alphanumerics using the %[A-Za-z0-9], then just use that in the combination with the other characters found in that string.
@bharatnarayana8401
@bharatnarayana8401 3 жыл бұрын
@@CodeVault {\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"} this is not working {"%[A-Za-z0-9]","%[A-Za-z0-9]","%[A-Za-z0-9]","%[A-Za-z0-9]"} this works..?
@CodeVault
@CodeVault 3 жыл бұрын
@@bharatnarayana8401 Yep. You just need to not forget about the \ before each " Sorry for the late reply
@asifsaad5827
@asifsaad5827 4 жыл бұрын
btw why did you write Point *p=points +i? can't we do like this Point *p=points[i] ?
@CodeVault
@CodeVault 4 жыл бұрын
No. points[i] is equivalent to *(points + i) which returns type Point Which means it would dereference that point. But we want a pointer to it, not the actual value since we want to modify the contents of that array. &points[i] would be equivalent to points + i which returns the type Point*
@asifsaad5827
@asifsaad5827 4 жыл бұрын
@@CodeVault why did you use a pointer to insert elements into an array? can't you simply put the values of x,y and val (during every loop) in the array named "points"?
@asifsaad5827
@asifsaad5827 4 жыл бұрын
@@CodeVault like this int i=0; while(!foef(file)) { sscanf(buffer,"%d %d %d",&points[i].x,&points[i].y,&points[i].val); i++; //rest are as usual }
@CodeVault
@CodeVault 4 жыл бұрын
Yep, you can. It was just shorter to write that way. I prefer to have a pointer to the iterated element in the array rather than repeating points[i] everywhere.
@kibisovnikita72
@kibisovnikita72 3 жыл бұрын
When is the next video?
@CodeVault
@CodeVault 3 жыл бұрын
Next week
@stickshift583
@stickshift583 3 жыл бұрын
Thank you!
@taherrezzag9848
@taherrezzag9848 4 жыл бұрын
but why you put fgets() out of while loop
@CodeVault
@CodeVault 4 жыл бұрын
It's so that you always call fgets right before checking if you're at the end of file. You could also call it inside but check it twice: while (!feof(file)) { fgets(buffer, 200, file); if (feof(file)) { break; } }
@asifsaad5827
@asifsaad5827 4 жыл бұрын
@@CodeVault why did you write an If statement inside while loop? when the file reaches the end of it, then will simply be out of the loop due to the condition set by the while loop
@CodeVault
@CodeVault 4 жыл бұрын
This is assuming that you also process this data in some way. Like this: while (!feof(file)) { fgets(buffer, 200, file); if (feof(file)) { break; } // Processing goes here sscanf(buffer, ...); } If we don't add that if statement, fgets wouldn't read anything and that would prompt sscanf to process the previous value that was in buffer thus duplicating the value (similarly to how I showed in the video)
@asifsaad5827
@asifsaad5827 4 жыл бұрын
@@CodeVault what if there is only one line of input in txt file? then what ? it won't enter the while loop ?? right?
@mongraal2272
@mongraal2272 2 жыл бұрын
thank u bro
@gabrielcalper6295
@gabrielcalper6295 4 жыл бұрын
I'm Brazilian(not English speaker) learning this in English is easier than my teacher lecturing hahahahahahhhaha
@maedesolgi8251
@maedesolgi8251 2 жыл бұрын
Thanks
@armandolopezespinoza3823
@armandolopezespinoza3823 4 жыл бұрын
Read json array of object deserialize on struct, please
@taherrezzag9848
@taherrezzag9848 4 жыл бұрын
thanks for help
@sagarbasnet6088
@sagarbasnet6088 4 жыл бұрын
please make video about List in C.
@CodeVault
@CodeVault 4 жыл бұрын
Here's a playlist for linked lists in C, hope this helps: kzbin.info/aero/PLfqABt5AS4FmXeWuuNDS3XGENJO1VYGxl
@relaxingweathersoundsrainy1138
@relaxingweathersoundsrainy1138 4 жыл бұрын
you are the best 🤗🤗🤗
@naruz5262
@naruz5262 3 жыл бұрын
I love your videos , please consider making a patreon , i would love to contribute to make this channel bigger ...
@CodeVault
@CodeVault 3 жыл бұрын
Thank you! We just launched the new website and it now has a shop where you can buy educational materials. If you find something useful there feel free to get as all the money goes into supporting this channel and community: code-vault.net/shop
@armandolopezespinoza3823
@armandolopezespinoza3823 4 жыл бұрын
Le di la campanita
List files in a directory (recursively too!)
13:28
CodeVault
Рет қаралды 44 М.
Read And Write An Array Of Structs To A Binary File | C Programming Example
18:27
Kluster Duo #настольныеигры #boardgames #игры #games #настолки #настольные_игры
00:47
She's very CREATIVE💡💦 #camping #survival #bushcraft #outdoors #lifehack
00:26
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 54 МЛН
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 10 МЛН
Structs in C | What you Need to Know
24:39
Caleb Curry
Рет қаралды 10 М.
Dynamically Allocate An Array Of Structs | C Programming Tutorial
15:11
Portfolio Courses
Рет қаралды 35 М.
Why Function Pointers are Awesome
11:11
Jacob Beningo
Рет қаралды 8 М.
Reading/Writing structs to files (aka Serialization)
14:41
CodeVault
Рет қаралды 76 М.
What are variadic functions (va_list) in C?
13:49
CodeVault
Рет қаралды 22 М.
What's the Best Way to Copy a Struct in C and C++?
13:44
Jacob Sorber
Рет қаралды 34 М.
Writing to text files in C
14:33
CodeVault
Рет қаралды 35 М.
struct Basics | C Programming Tutorial
24:44
Portfolio Courses
Рет қаралды 143 М.
Kluster Duo #настольныеигры #boardgames #игры #games #настолки #настольные_игры
00:47