I've really appreciated the videos you've made on C programming. College did not leave me with a very strong grasp of lower level programming languages like C and so I've been going through all your videos on C programming; they have been an absolute treasure trove. Unlike other tutorials, you make it a point to explain all the standard functions that are at your disposal and how you may want to use them in different circumstances, and you also make it a point to explain why you are doing what you are doing when it comes to manual memory management. You're a legend 💪🏽
Thank you very much for sharing this kind feedback with me, it's very encouraging for me to hear that these videos are helping you out and that you're enjoying the teaching style. :-D
The best C programming tutorial series ever! I feel so satisfied that I now know everything you taught. For the starters to C, I highly recommend to follow the whole playlist.
I am 100% sure when saying this that you got some of the best, most high quality content right here. In school they didnt explain files very well and this video did it in 20 minutes. Thank you so much
This was very helpful, thank you so much! Also I know it's 2 year's old but this video is rock solid and the instruction's and explaination's are great!
i really appreciae your effort, and i like the way you explain things and make it easier and smooth, but i've a question that popped up in to my mind, why either fgets or fscanf get into the new line just by using while without doing increment to the new line !
I think it's because of the file position indicator inside our object of the type FILE , I know it may sound complicated but it's not !! when we say FILE *object = fopen("x.txt","r") ; we are actually creating a variable(object) of type struct and inside this struct there is variable that changes each time we call fgets or fgetc .. notice every time we call those function we are passing our object of of FILE(struct) type as pointer so changes will apply and remain in our main object, maybe my explanation is not totally accurate because object is a pointer of type FILE but I think the logic of it is like that. the question that popped up into my mind is how is it possible write to a txt file the same way u write to the console, it's strange to me and it does not make sense but I did some researches and people are saying that everything in our computers is files,what the F**k they mean by that , it does not make any sense , it does not make any sense because our brains get mess up with too much abstraction from windows,I think an operating system course is needed to understand these topics so yea I'm going to take one, sorry if I wasted your time !!
Great question! :-) Basically, if we store data into variables, the data will disappear when our program stops execution. Storing data into a file allows us to retrieve the data later, even if we restart our program, or even our computer. Storing data into a file also allows us to make copies of the file, and share the file with others.
Great question Steve. 🙂 Where is the output in the terminal coming form? Is it text that the user is typing in? Or is it output from the program that is running?
Great question Saud! :-) You could do something like this: fscanf(file, "%f %f", &dblvar1, &dblvar2); You might find this related video interesting: ruclips.net/video/Gaq10GBlRJA/видео.html
Great question Krishna! :-) I am using Terminal on Mac OS, which is a "bash shell", a type of shell that is used in Unix-like systems like Linux and Mac OS. A Windows shell is different and does not support the same commands. So something like 'touch' will not work on Windows. You could use a text editor instead to create a file and open it though. In many situations Windows will have a command that allow us to do 'the equivalent' of what we can do with a Terminal command: stackoverflow.com/a/37756874. It's also possible to get a Linux shell on Windows using things like Windows Subsystem for Linux, but that can be a fair bit of work and would be challenging for new beginners I think (though it may be a good learning experience).
Basically the feof() function returns true when we reach the end of a file, and false otherwise. This explains more: www.tutorialspoint.com/c_standard_library/c_function_feof.htm. I may try to make a video on feof() specifically though, that might be something people would be interested in. :-)
@@PortfolioCourses thanks for the response.Can u see this statement is this correct? It's important to note that feof only tells you if you've reached the end of the file after you've tried to read past it.
You're welcome Mohammad! 🙂 Maybe one day I can create a course on advanced C, but I think a course on advanced C would probably be many courses covering different subtopics like threads, networking, etc.
I need some help please, I'm trying to read integers from a .txt file and add them together. The problem is the file also contains letters, kinda like this: Peter 20 Frank 30 Joe 40.... I want to ignore letters completely and just add the numbers together, too tricky for me....
So there isn't really a super easy answer to this question, it's a bit tricky. There are a few ways you could do it. :-) You could read each entire line into a string (char array) and then use strtok() to pull out the integer you're interested in. These examples might help with that approach, the link to the video tutorial is at the top of the file in the comments: github.com/portfoliocourses/c-example-code/blob/main/file_lines_to_string_array.c github.com/portfoliocourses/c-example-code/blob/main/strtok.c Another way to do it would be closer to the way this 'read from CSV file' example uses fscanf(), again the link to the video is at the top of the file: github.com/portfoliocourses/c-example-code/blob/main/csv_to_struct_array.c So at the bottom of that code there is a loop that uses fscanf() to read the data from the file. If you had variables: char name[2048]; int number; You could then have fscanf: fscanf(file,%2048[^0123456789]%d ",name,&number); To read in each number, in a similar way to that example. You would then have to add the numbers together.
@@PortfolioCourses Wow thanks dude, I'm gonna go through all of this step by step. There is so much to learn😮... I remember someone saying "C is easy and beginner friendly, it only has 32 keywords". 🤣 By the way your content is absolutely GREAT.🏆🥇🏆
@@iGavid_Doggins Oh wow haha I would say C is one of the less forgiving languages, especially compared to something like Python. 🙂 And thank you for the kind words I'm glad to hear you enjoy the content!
Maybe I'll make a video on this soon! In the meantime, this answer here is pretty good, you basically can use fscanf() with %f and %lf to read in floats and doubles from a file: stackoverflow.com/a/7152018
I want to ask what is the meaning of exit(1)/exit(-1) FILE *pd; if((pd = fopen("test","w")) == NULL) { puts("Can`t be done."); exit(-1); } Is the same as return 0/1; ??
Great question Pagani! :-) When we call exit() the program will exit, and the argument we provide to exit() will be the status code. If we have exit(0) the program will exit with status code 0, which is considered 'success'. If we have exit(1) or exit(-1) the program will exit with status code 1 or -1, both of which are considered 'error' (any non-zero exit status code is considered 'error'). When we use return 0 in main the program will exit with status 0, and if we use return 1 in main the program will exit with status 1. But we can only use return to exit the program in main. If we want to exit the program in other functions, we can use exit instead. So that's the biggest difference.... with exit we can exit the program in any function. This video covers exit(): ruclips.net/video/8RucxSeAemw/видео.html. The other thing we can do with exit is setup functions to run when the program exists, this video covers that topic: ruclips.net/video/Ik3nzpn5LoE/видео.html. Hopefully this helps! :-)
Great question Pagani! :-) We could use "a" for append and that will also create the file if it doesn't exist. This article does a good job talking about the different access modes: www.geeksforgeeks.org/basics-file-handling-c/.
Great question Emanuel! :-) Though the answer is essentially.... because that's how fgets() works. It stops at the first newline it encounters. If you want to read all the file contents into a string this video might help with that: ruclips.net/video/CzAgM5bez-g/видео.html.
I've really appreciated the videos you've made on C programming. College did not leave me with a very strong grasp of lower level programming languages like C and so I've been going through all your videos on C programming; they have been an absolute treasure trove. Unlike other tutorials, you make it a point to explain all the standard functions that are at your disposal and how you may want to use them in different circumstances, and you also make it a point to explain why you are doing what you are doing when it comes to manual memory management. You're a legend 💪🏽
Thank you very much for sharing this kind feedback with me, it's very encouraging for me to hear that these videos are helping you out and that you're enjoying the teaching style. :-D
Could u help me understand how to store and edit information in a file that's in like a table?
Great job. Way better that the top results on the topic. Much appreciated.
Thank you very much for the kind feedback! :-)
The best C programming tutorial series ever! I feel so satisfied that I now know everything you taught. For the starters to C, I highly recommend to follow the whole playlist.
For this 24min long video full of quality information, I just want to thank you!
You're very welcome! :-)
I am 100% sure when saying this that you got some of the best, most high quality content right here. In school they didnt explain files very well and this video did it in 20 minutes. Thank you so much
Amazing that you still read the comments on these videos.
God bless you for that
Thank you! I love reading the comments, the people that watch these videos tend to be very supportive. :-)
This was very helpful, thank you so much! Also I know it's 2 year's old but this video is rock solid and the instruction's and explaination's are great!
Thanks for this! Really clear and easy to understand.
You're welcome! I'm glad to hear you found it clear and easy to understand. :-D
The explanation is crystal clear... great job sir...
Thank you, I'm glad you enjoyed it! :-)
there is a course on Udemy that costs about 3000/4000 rupees and this playlist is way better than that course
well done! and thanks a lot!
before watching your videos , I click like because I know for sure its going to be great, keep up the great content sir.
I'm so glad to hear you're enjoying the content, and thank you for the support Okibe! :-)
This is an awesome tutorial man, thanks a lot.
You're welcome! 😀
Thank u DR kevin, your tutorials are the best.
You’re welcome, I’m glad you enjoy the tutorials! :-)
Nothing better than C.
I agree. :-)
i really appreciae your effort, and i like the way you explain things and make it easier and smooth, but i've a question that popped up in to my mind, why either fgets or fscanf get into the new line just by using while without doing increment to the new line !
I think it's because of the file position indicator inside our object of the type FILE , I know it may sound complicated but it's not !! when we say FILE *object = fopen("x.txt","r") ; we are actually creating a variable(object) of type struct and inside this struct there is variable that changes each time we call fgets or fgetc ..
notice every time we call those function we are passing our object of of FILE(struct) type as pointer so changes will apply and remain in our main object,
maybe my explanation is not totally accurate because object is a pointer of type FILE but I think the logic of it is like that.
the question that popped up into my mind is how is it possible write to a txt file the same way u write to the console, it's strange to me and it does not make sense but I did some researches and people are saying that everything in our computers is files,what the F**k they mean by that , it does not make any sense ,
it does not make any sense because our brains get mess up with too much abstraction from windows,I think an operating system course is needed to understand these topics so yea I'm going to take one, sorry if I wasted your time !!
very helpful video man ngl, thanks for sharing this knowledge for free
You're welcome! 🙂
best tutorials on youtube, thank you so much 🙂
You're very welcome, and thank you for the kind feedback! :-)
to the point and excellent explanation, your videos are treasure trove
Literally 🥶 your video is so amazing and useful for college students!
You saved my technical interview ☺
I’m glad to hear this helped you Edward, and I hope you get the job! :-)
thank you so much, you saved my assignment
You’re very welcome, and good luck on the assignment! :-)
Thanks bro! Always helping
You’re welcome! Thanks for all the encouraging feedback.
its really good explanation and tutorial
thanks.
You’re welcome Yusuf! :-)
Thanks for this great tutorial!
You're welcome! :-D
do you also have a tutorial on open instead of fopen? i'm starting with the basics... taking steps before i run
nice explanation, I really appreciate this.
You're welcome Abdelmuniem, I'm glad you enjoyed the explanation! :-)
Great video!
awsome video like allways best explain ever..thank you for all the hard work you put to help us..
your awsome.. :)
You're welcome Idan I'm glad you enjoyed the explanation, and thank you for the very positive and encouraging feedback too. :-)
There's only one thing missing. Why do we need to use file, and what benefits they offer . Because, this is usually asked in the interview questions.
Great question! :-) Basically, if we store data into variables, the data will disappear when our program stops execution. Storing data into a file allows us to retrieve the data later, even if we restart our program, or even our computer. Storing data into a file also allows us to make copies of the file, and share the file with others.
the GOAT
I wish you were my professor!!
Aww thanks Barkot that is such nice positive feedback and it means a lot to me! :-)
That's really helpful , thanks alot
You're welcome! 😀
What is when my input file had a unknow size of lines? But i wan't to have all in the buffer?
You might find this video interesting if I’m understand what you are asking correctly: ruclips.net/video/Oa_ji3dDFew/видео.htmlsi=ZOfk9MAH--lfCKV1
And this video may be of interest too: ruclips.net/video/vQno9S3yF80/видео.htmlsi=rnRtjymSMC5jjI2F
can you please do a video about files and structures in c
Like reading data from a file into a struct?
This video is a big "W"
I’m glad you enjoyed it! :-)
How to generate all output in terminal into .dat file?
Great question Steve. 🙂 Where is the output in the terminal coming form? Is it text that the user is typing in? Or is it output from the program that is running?
hello!, what if I want to read a second number on the same line seperated by a space from the first
Great question Saud! :-) You could do something like this:
fscanf(file, "%f %f", &dblvar1, &dblvar2);
You might find this related video interesting: ruclips.net/video/Gaq10GBlRJA/видео.html
Thank you!
Which command-line interface are you using,sir? I can't use 'touch',vi commands in my windows 11 terminal or command prompt. What do I have to do...?😒
Great question Krishna! :-) I am using Terminal on Mac OS, which is a "bash shell", a type of shell that is used in Unix-like systems like Linux and Mac OS. A Windows shell is different and does not support the same commands. So something like 'touch' will not work on Windows. You could use a text editor instead to create a file and open it though. In many situations Windows will have a command that allow us to do 'the equivalent' of what we can do with a Terminal command: stackoverflow.com/a/37756874. It's also possible to get a Linux shell on Windows using things like Windows Subsystem for Linux, but that can be a fair bit of work and would be challenging for new beginners I think (though it may be a good learning experience).
Can u explain feof function?
Basically the feof() function returns true when we reach the end of a file, and false otherwise. This explains more: www.tutorialspoint.com/c_standard_library/c_function_feof.htm. I may try to make a video on feof() specifically though, that might be something people would be interested in. :-)
@@PortfolioCourses thanks for the response.Can u see this statement is this correct?
It's important to note that feof only tells you if you've reached the end of the file after you've tried to read past it.
I believe that statement is correct, yes. :-)
Here you go, a new video on the feof() function: ruclips.net/video/Ui0idK9Dh04/видео.html
you are the goat
thanks for video ! 😉😉🧡🧡🧡🧡 , please create new course for advanced c and using c in real project
You're welcome Mohammad! 🙂 Maybe one day I can create a course on advanced C, but I think a course on advanced C would probably be many courses covering different subtopics like threads, networking, etc.
I need some help please,
I'm trying to read integers from a .txt file and add them together.
The problem is the file also contains letters, kinda like this: Peter 20
Frank 30
Joe 40....
I want to ignore letters completely and just add the numbers together,
too tricky for me....
Some additional info,
the way I wrote to the file was: fprintf(fp, "Peter %d
", userNames(varOne));
So there isn't really a super easy answer to this question, it's a bit tricky. There are a few ways you could do it. :-) You could read each entire line into a string (char array) and then use strtok() to pull out the integer you're interested in. These examples might help with that approach, the link to the video tutorial is at the top of the file in the comments:
github.com/portfoliocourses/c-example-code/blob/main/file_lines_to_string_array.c
github.com/portfoliocourses/c-example-code/blob/main/strtok.c
Another way to do it would be closer to the way this 'read from CSV file' example uses fscanf(), again the link to the video is at the top of the file:
github.com/portfoliocourses/c-example-code/blob/main/csv_to_struct_array.c
So at the bottom of that code there is a loop that uses fscanf() to read the data from the file. If you had variables:
char name[2048];
int number;
You could then have fscanf:
fscanf(file,%2048[^0123456789]%d
",name,&number);
To read in each number, in a similar way to that example. You would then have to add the numbers together.
@@PortfolioCourses Wow thanks dude, I'm gonna go through all of this step by step.
There is so much to learn😮... I remember someone saying "C is easy and beginner friendly, it only has 32 keywords". 🤣
By the way your content is absolutely GREAT.🏆🥇🏆
@@iGavid_Doggins Oh wow haha I would say C is one of the less forgiving languages, especially compared to something like Python. 🙂 And thank you for the kind words I'm glad to hear you enjoy the content!
thank you
it doesn't work on codeblocks doesn'it ?
Can you tell what compiler you are using
In this video I am using Visual Studio Code as a text editor and the gcc compiler with the terminal on a Mac. :-)
How do I extract a float number from a text file? lol
Maybe I'll make a video on this soon! In the meantime, this answer here is pretty good, you basically can use fscanf() with %f and %lf to read in floats and doubles from a file: stackoverflow.com/a/7152018
I want to ask what is the meaning of exit(1)/exit(-1)
FILE *pd;
if((pd = fopen("test","w")) == NULL)
{
puts("Can`t be done.");
exit(-1);
}
Is the same as return 0/1; ??
Great question Pagani! :-) When we call exit() the program will exit, and the argument we provide to exit() will be the status code. If we have exit(0) the program will exit with status code 0, which is considered 'success'. If we have exit(1) or exit(-1) the program will exit with status code 1 or -1, both of which are considered 'error' (any non-zero exit status code is considered 'error'). When we use return 0 in main the program will exit with status 0, and if we use return 1 in main the program will exit with status 1. But we can only use return to exit the program in main. If we want to exit the program in other functions, we can use exit instead. So that's the biggest difference.... with exit we can exit the program in any function. This video covers exit(): ruclips.net/video/8RucxSeAemw/видео.html. The other thing we can do with exit is setup functions to run when the program exists, this video covers that topic: ruclips.net/video/Ik3nzpn5LoE/видео.html. Hopefully this helps! :-)
@@PortfolioCourses wow, thank you !
@@paganimarker1898 You're welcome! 🙂
thank you so much
You're very welcome Robel! :-)
Thanks sir
is "w" the only way to create file?
Great question Pagani! :-) We could use "a" for append and that will also create the file if it doesn't exist. This article does a good job talking about the different access modes: www.geeksforgeeks.org/basics-file-handling-c/.
@@PortfolioCourses Thank you
You're welcome! :-)
underrated channel (^_^)
Thank you Vinamr! :-D
Good
Thank you David! :-)
why fgets() read only first line of "in.txt" ? because in "in.txt" i wrote more than one line by sending a new line. thank you!!
Great question Emanuel! :-) Though the answer is essentially.... because that's how fgets() works. It stops at the first newline it encounters. If you want to read all the file contents into a string this video might help with that: ruclips.net/video/CzAgM5bez-g/видео.html.
@@PortfolioCourses i just watched the video and it's great the way you explain it, thank you very much!!
@@emanuel_ramaci Awesome, and you're welcome! 🙂
This is a great tutorial, thanks!
thank u so much
You're welcome, I'm glad you enjoyed the video! :-)