C Programming Tutorial 69, Reading From Files pt.2

preview_player
Показать описание

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

Your videos are so amazing. Keep it up!

dennislarsen
Автор

And by the way, love your tutorials! Very clear, well explained and provides good examples! Appreciate your work.

"yup, perfect!" ;)

TheEpicAndrew
Автор

Been searching for a tutorial on this for HOURS. Finally something helpful.
T H A N K Y O U !!

TShrivastava
Автор

What if we did not use structs and just did arrays? How would we use the malloc command on arrays for the strings?

zachs
Автор

Emm yes, more or less. I just got used to some things, that I can/cannot do on my PC in Visual Studio :) Thanks for help!

TheEpicAndrew
Автор

great video.
can you program a c++ version of this program using classes and objects?
i tried using class instead of tydef struct and declaring *name and score inside private but it doesn´t compile it says "invalid conversion from void* to entry", i apreciate you help.

rafaellindarte
Автор

The file:

4
4 Adam 53243
4 Mary 52134
7 Jackson 48921
4 Beth 47202

adi_trades
Автор

Does the fscanf function move automatically to the next item? because it seems to be this way

marian_f
Автор

Yea, I did. I can declare variable, only if it is after curly brace in a scope. Thus I had to declare Entry *entries at the beginnig, and then I could malloc them.

TheEpicAndrew
Автор

what's the difference between typedef structure and simple structure? when do you use which? p.s. amazing tutorial, helped a lot :)

Lina-mbvt
Автор

The builder cannot find myfile.txt. Do I need to configure something first ?

mozamota
Автор

How you manage to declare variables inside the code? I thought C requires all declarations at the beginning of the function.
And in Visual studio i get an error, since malloc returns pointer of type void and it 'cannot be used to initialize an entity of type "Entry*" '. Although I fix this by writing it in such way:
entries = (Entry*) malloc(sizeof(Entry) * entryCount);
I'm just wondering, does it depend on compiler? Or on system/pc?

TheEpicAndrew
Автор

Did you include stdlib.h? Since malloc actually returns a void* (a pointer to nothing), some compilers apparently might want an explicitly cast to the type you want. Apparently yours does? Many examples I've seen use a cast although on my linux machine with gcc, I don't have to (as long as I include stdlib.h).

As for the variable declaration inside the code, I think that's been allowed since C99. So the general rule-of-thumb is to declare them as close as possible to where they'll be used.

tcbetka
Автор

What happen if we dont leave a space for the \0 ? Like instead of writing nameLen+1 we just write nameLen?

ljk
Автор

I'm not sure what you're saying, in terms of what exactly the problem is/was. However it sounds like you got it resolved, so maybe there's no more problem?

tcbetka
Автор

why didn't we malloc the score if we had to malloc the entry[i].name?
and wouldn't the fscanf function read from the beginning of a file everytime its called?
like when its called the first time, its to read the number of entries. and when called again, wouldn't it start over and read the first character again? i have the same confusion regarding the fgetc function in the previous video! little help please?! 

simransingh
Автор

sorry nevermind i just changed the quality to a higher one and bam it fixed it.

Educationscience
Автор

the screen is so small that i can't even read what's in that text file. what the hell man. ZOOM IN!!!???

Educationscience
Автор

5:56 why doesnt "entries[i].name" have "&", you just wrote "&" into "entries[i].score"

johnbalvin
Автор

how come your computer didn't have to define "i"??

johnchen