Roses are red, Violets are blue, You grind every day, Bro, I respect you. Coding all night, With coffee in hand, Debugging those errors, I totally understand. Stay on the hustle, You’ve got what it takes, Bro, keep on pushing, Success never breaks. 🌟
if anyone is getting an error/segmentation fault when testing with a non existent file, move the fclose() inside the else. fclose can't close a file that is not open so it will segment fault...
Hey man awesome video! Would it be possible if you made a video on registering a word and line number where the word first appears in a dictionary? And then print the words and line numbers. Have an awesome day!
What if I want to read from a specific line? Using your file as an example, what would I need to do to make it read just BOOTY BOOTY BOOTY BOOTY in stdout?
if you know the number of which line BOOTY BOOTY BOOTY BOOTY is on, you can make a counter which counts each loop and put the print statement inside an if(counter == the correct line number). then the program wont print any of the other lines in the file.
I noticed some weird behaviour with this one, what could the case be? Initially I made a text document with 3 lines, the while loop skipped the first line and printed the remaining 2 no problem. I edited the file and put the numbers 1-6 on respective lines, and it only printed the even ones. I don't understand why this is happening!
Very nice explanation thank you so much! I only got one question: your char array consists of 255 chars and you allow fgets() to read 255 characters. But a string always needs \0 at its end so I am used to either declare the string like: char buffer[255 + 1] or read one element less like: fgets(buffer, 254, pF). Isn't that necessary when reading files or was it a mistake in the code? Cheers!
From ChatGPT: You're correct. A null-terminator (`\0`) is necessary to mark the end of a C string. If you have an array of 255 characters, reading exactly 255 characters without accounting for the null-terminator can lead to undefined behavior or buffer overflow issues.
Hi i have followed your video step by step. Unfortunately i am still tagging for "Error: could not open file .txt for reading". I do not understand as to why i am, if anyone has any answers PLS HELP.
#include
int main()
{
FILE *pF = fopen("poem.txt", "r");
char buffer[255];
if(pF == NULL)
{
printf("Unable to open file!
");
}
else
{
while(fgets(buffer, 255, pF) != NULL)
{
printf("%s", buffer);
}
}
fclose(pF);
return 0;
}
how can we do it using fscanf?!
Hello bro thanks for your amazing teaching,but I have problem of reading file using mingw32
your poem was truly the GOAT of all poems and to think you are a code youtuber
Roses are red,
Violets are blue,
You grind every day,
Bro, I respect you.
Coding all night,
With coffee in hand,
Debugging those errors,
I totally understand.
Stay on the hustle,
You’ve got what it takes,
Bro, keep on pushing,
Success never breaks. 🌟
bro... this is beautiful
@LilNuggette thank you
if anyone is getting an error/segmentation fault when testing with a non existent file, move the fclose() inside the else. fclose can't close a file that is not open so it will segment fault...
Good catch!
Best explanation for reading files on youtube!
In my opinion there are no better teaching channel than 'bro code'';
Roses are red
Violets are blue
This video is awesome
Scooby doo be doo
now replace oo with ee
@@badmassfuryku1665 brainrotmaxxing
Very useful
Thank you very much
Hope you will keep making such useful contents
Hey man awesome video! Would it be possible if you made a video on registering a word and line number where the word first appears in a dictionary? And then print the words and line numbers.
Have an awesome day!
Your videos are goated, subscribing fs
Here's code I made to read a file:
#include
#include
#include
#include
#include
#include
#include
int main(){
FILE *pFile = fopen("C:\\Users\\squee\\Desktop\\Hello.txt","r");
if(pFile == NULL){
printf("Hello.txt does not exist :(");
}
else{
char buffer[256];
while(fgets(buffer,256,pFile) != NULL){
printf("%s",buffer);
}
}
fclose(pFile);
}
great, but u don't need all the #includes
This video saved me from a big disaster!!!!
tq so much....
Just a quick message, you do not need != NULL in aloop, since when function fails, an execption is thrown automTically
I love your videos man
Love you bro!
What if I want to read from a specific line? Using your file as an example, what would I need to do to make it read just BOOTY BOOTY BOOTY BOOTY in stdout?
if you know the number of which line BOOTY BOOTY BOOTY BOOTY is on, you can make a counter which counts each loop and put the print statement inside an if(counter == the correct line number). then the program wont print any of the other lines in the file.
I noticed some weird behaviour with this one, what could the case be?
Initially I made a text document with 3 lines, the while loop skipped the first line and printed the remaining 2 no problem.
I edited the file and put the numbers 1-6 on respective lines, and it only printed the even ones. I don't understand why this is happening!
4:00 why not to just cloes file and return 1 in this if statement?
nicely done!
Very helpful playlist
Thank you
im opening one and i get a bunch of letters
Very nice explanation thank you so much! I only got one question: your char array consists of 255 chars and you allow fgets() to read 255 characters. But a string always needs \0 at its end so I am used to either declare the string like: char buffer[255 + 1] or read one element less like: fgets(buffer, 254, pF). Isn't that necessary when reading files or was it a mistake in the code? Cheers!
From ChatGPT:
You're correct. A null-terminator (`\0`) is necessary to mark the end of a C string. If you have an array of 255 characters, reading exactly 255 characters without accounting for the null-terminator can lead to undefined behavior or buffer overflow issues.
will you make a video on fscanf?
learned a bunch!
Tried this on a C compiler on an Android. Result is "Segmentation fault/core dumped". What gives?
Android file system =/= Windows file system is my guess
thank you very muh!
my terminal is not workin on me , why?
Thanks bro
Mingw32 cannot open file output ,help please
Hi i have followed your video step by step. Unfortunately i am still tagging for "Error: could not open file .txt for reading". I do not understand as to why i am, if anyone has any answers PLS HELP.
Are compile on android, if yes then that's the problem, it requires a laptop compiler e.g VS code
Does anyone know if it'll work in c++?
0:10 can you dm me the codes inside the first folder I need them for a prank