Finding C programming hard? We’ve got you! 🚀Get 60% off on Programiz PRO Lifetime Plan this Black Friday-pay once for skills that last forever. Don’t miss out, it’s a limited-time offer! 👉Grab your discount now: bit.ly/blkfriday-24-yt
If u don't want to remove all the previous contents of the file when u write in it, u can use append instead. The syntax is fptr = fopen("text.txt", "a");
If you create a file via write mode, or append mode, try naming your file aux FILE *file1; file1=fopen("aux.txt","w"); the file with this name won't be created naming a file aux is forbidden in Windows, try creating a folder r text document and naming it aux... just some random stuff to spice things up
#include int main(){ FILE* fptr; fptr = fopen("1.txt","w"); char contant[1000]; fputs("C is a fun programming language ",fptr); fputs("And,I love using C language :)",fptr); fclose(fptr); fptr = fopen("1.txt","r"); while(fgets(contant, 1000, fptr)){ printf("%s",contant); } return 0; }
how to setting when you run code the visual code show the time executing those code? I saw you just click run code and there are time of executing code available there.
/* * Create a new file in write mode * Write Content * C is a fun programming language. * And, I love using C language * Close the file * Again open the file in read mode and read the content of the file */ #include int main(){ FILE* fptr; fptr = fopen("newText.txt", "w"); fputs("C is a fun programming language.",fptr); fputs(" And, I love using C language",fptr); fclose(fptr); fptr = fopen("newText.txt", "r"); char content[1000]; if (fptr != NULL){ while (fgets(content, 1000, fptr)){ printf("%s", content); } }else{ printf("File Open Unsuccessful"); } fclose(fptr);
shouldn't the fclose() be inside if block, at its end. As in case of unsuccessful opening of file (execution of else statement) , fclose() doesn't make any sense. Please correct me if I'm wrong
is there another we condition we can use for that, because that doesnt realy make sense in my head,,, that statement does not return true or false, it just stores the line into the array
The fgets statement doesn't return true or false but it does return a non-Null pointer as it reads a line from the file and stores it in the 'content' array, which is evaluated as true in the loop's condition, causing the loop to continue. Once fgets reaches the end of the file, it returns a NULL pointer, which is evaluated as false in the loop's condition, causing the loop to terminate.
How can we open a file in a "for loop and create different files for each size of arrays. For example: For () { file 1 for array[0] File 2 for array[1].….. }
#include int main() { // Write C code here FILE* fptr; fptr=fopen("File.txt","w"); char content[1000]; fputs("C is a fun programming language",fptr); fputs("And I love C language",fptr); fptr=fopen("File.txt","r"); fgets(content,1000,fptr); fclose(fptr); return 0; } It shows the segmentation fault error in the online c programming
#include #include // Include for exit() function int main() { FILE* fptr; char content[1000]; char userInput[1000]; // Open the file in write mode fptr = fopen("NewFile.txt", "w"); if (fptr == NULL) { printf("Error opening file. "); exit(1); } // Prompt the user to enter text printf("What do you want to add in NewFile.txt? "); fgets(userInput, sizeof(userInput), stdin); // Write user input to the file fputs(userInput, fptr); // Close the file fclose(fptr); // Open the file in read mode fptr = fopen("NewFile.txt", "r"); if (fptr == NULL) { printf("Error opening file. "); exit(1); } // Read and print the contents of the file printf("Contents of NewFile.txt: "); while (fgets(content, sizeof(content), fptr)) { printf("%s", content); } // Close the file fclose(fptr); return 0; }
// Online C compiler to run C program online #include int main() { FILE* fptr; fptr = fopen("one piece.txt","r"); char content[1000]; fputs("i love one piece anime ",fptr); fputs("the most one that i love in one piece is lufy", fptr); fclose(fptr); fptr = fopen("one piece.txt","r"); while(fgets(content, 1000, fptr)){ printf("%s",content); } return 0; }
#include int main() { FILE* fptr; fptr = fopen("newFile.txt", "w"); fputs("C is a fun programming language ", fptr); fputs("And, I love using C language", fptr); fclose(fptr); char content[1000]; fptr = fopen("newFile.txt", "r"); if (fptr != NULL) { while (fgets(content, 1000, fptr)) { printf("%s", content); } } else { printf("File Open Unsuccessful"); } fclose(fptr); return 0; }
Finding C programming hard? We’ve got you!
🚀Get 60% off on Programiz PRO Lifetime Plan this Black Friday-pay once for skills that last forever. Don’t miss out, it’s a limited-time offer!
👉Grab your discount now: bit.ly/blkfriday-24-yt
If u don't want to remove all the previous contents of the file when u write in it, u can use append instead.
The syntax is
fptr = fopen("text.txt", "a");
I was wondering about this. Thanks
Thank u bro🎉
the answer's B! Also, this vid's amazing; i got my programmin exam in a few hours, thank a bunch!
Tmrw is my programing final in engineering this just saved my life
If you create a file via write mode, or append mode, try naming your file aux
FILE *file1;
file1=fopen("aux.txt","w");
the file with this name won't be created
naming a file aux is forbidden in Windows, try creating a folder r text document and naming it aux...
just some random stuff to spice things up
I think the same with "con.txt"
oh accha
finally programming in vs code 😍
and thanks for the video ma'am
09:50 returns True True 😅
it really helps me improve my knowledge about c programing
Option B is answer
#include
int main(){
FILE* fptr;
fptr = fopen("1.txt","w");
char contant[1000];
fputs("C is a fun programming language
",fptr);
fputs("And,I love using C language :)",fptr);
fclose(fptr);
fptr = fopen("1.txt","r");
while(fgets(contant, 1000, fptr)){
printf("%s",contant);
}
return 0;
}
you forgot to close the file again after reopening
@@kfirezer I think some data of file will be loss if he didn`t do that?
@@countrysideshowyaigrock4689 I don't think so, but it is a good practice since maybe you'll use unnecessary resources.
hii do you have tutorial on how to setup vscode
Thank you so much for this, helped me in my project like an angel!!
your content helps me a lot
Your way of teching . easy to undestand
Mam how to run the c code in vs code editor cause my code is not running and it shows 'gcc is not recognised '
Option B
wow, finaly i understood this !thank you a lot for this video👍👍👍👍
how to setting when you run code the visual code show the time executing those code? I saw you just click run code and there are time of executing code available there.
Code Runner VSC Extension.
/*
* Create a new file in write mode
* Write Content
* C is a fun programming language.
* And, I love using C language
* Close the file
* Again open the file in read mode and read
the content of the file
*/
#include
int main(){
FILE* fptr;
fptr = fopen("newText.txt", "w");
fputs("C is a fun programming language.",fptr);
fputs("
And, I love using C language",fptr);
fclose(fptr);
fptr = fopen("newText.txt", "r");
char content[1000];
if (fptr != NULL){
while (fgets(content, 1000, fptr)){
printf("%s", content);
}
}else{
printf("File Open Unsuccessful");
}
fclose(fptr);
return 0;
}
shouldn't the fclose() be inside if block, at its end. As in case of unsuccessful opening of file (execution of else statement) , fclose() doesn't make any sense.
Please correct me if I'm wrong
Option B : FILE* pointer;
---------------------------------------------------------------------------------------------------------------
#include
int main() {
FILE* file;
file = fopen("newFile.txt", "w");
fputs("C is a fun programming language
", file);
fputs("And, I love using C language", file);
fclose(file);
file = fopen("newFile.txt", "r");
char content[1000];
while (fgets(content, 1000, file)); {
printf("%s", content);
}
return 0;
}
Thank you so much for this video. Much needed. 👍🏻
B option
Quiz answer is B
Answer: B
11:34 Answer : b) FILE* pointer
amazing teacher
Great videos thank you very much.
Mine was 1000th like to the vid....😎😎
apart really helpful
thank you soooo much madam
quiz ans. b) FILE *Pointer;
Nice teaching
quiz answer option B
These. Video is really very helpful
Thank you!
Why doesnt this work for visual studio 2019. I feel there is something changed in syntax which needs to be modified . Can you please help me with it.
is there another we condition we can use for that, because that doesnt realy make sense in my head,,, that statement does not return true or false, it just stores the line into the array
The fgets statement doesn't return true or false but it does return a non-Null pointer as it reads a line from the file and stores it in the 'content' array, which is evaluated as true in the loop's condition, causing the loop to continue. Once fgets reaches the end of the file, it returns a NULL pointer, which is evaluated as false in the loop's condition, causing the loop to terminate.
Mam from where I can check this?
programming quiz:
#include
int main(){
FILE* fptr;
fptr = fopen("newfile.txt","w");
fputs("c is afum programming language
",fptr);
fputs("i love c language",fptr);
fptr= fopen("newfile.txt","r");
char content[1000]
if(fptr!=NULL){
fgets(content,1000,fptr);
printf("%s",content);
}
else{
printf("file open is unsuccessfull");
}
fclose(fptr);
return 0;
}
How can we open a file in a "for loop and create different files for each size of arrays.
For example:
For ()
{
file 1 for array[0]
File 2 for array[1].…..
}
Answer:b
Without closing the file how it's run
FILE* pointer
NO : Let me so you
USE : Let me show you
I actually like the way she says so instead of show lol
@@Titan_Design How about jero instead zero? I like her transcription too
programiz quiz : the ansewr is B
How to use a file when using a real program
To declare file pointer we use FILE.pointer
no..?
nice
What do i need to do if it thinks that the file doesnt have any text?
I dont know ur code so
#include
int main() {
// Write C code here
FILE* fptr;
fptr=fopen("File.txt","w");
char content[1000];
fputs("C is a fun programming language",fptr);
fputs("And I love C language",fptr);
fptr=fopen("File.txt","r");
fgets(content,1000,fptr);
fclose(fptr);
return 0;
}
It shows the segmentation fault error in the online c programming
option b
Quiz Answer:
B) FILE* fptr;
Sorry answer would be
B) FILE* pointer;
B. FILE* pointer;
one complier is showw much better
#include
#include // Include for exit() function
int main() {
FILE* fptr;
char content[1000];
char userInput[1000];
// Open the file in write mode
fptr = fopen("NewFile.txt", "w");
if (fptr == NULL) {
printf("Error opening file.
");
exit(1);
}
// Prompt the user to enter text
printf("What do you want to add in NewFile.txt?
");
fgets(userInput, sizeof(userInput), stdin);
// Write user input to the file
fputs(userInput, fptr);
// Close the file
fclose(fptr);
// Open the file in read mode
fptr = fopen("NewFile.txt", "r");
if (fptr == NULL) {
printf("Error opening file.
");
exit(1);
}
// Read and print the contents of the file
printf("Contents of NewFile.txt:
");
while (fgets(content, sizeof(content), fptr)) {
printf("%s", content);
}
// Close the file
fclose(fptr);
return 0;
}
B
She's Nepali
hi
Always a Indian
the girl who taught this is pretty
She is cute ,isn't she?
So...pretty
Simp ranmati
@@Baka100simp for thinking a girl is pretty? no wonder yall are third world countries
Programmers seeing a girl for the first time in months because they fell into programming spiral :
b
A
why are you so cute?
Aukat mai
5:52
Worst explanation ever .
// Online C compiler to run C program online
#include
int main() {
FILE* fptr;
fptr = fopen("one piece.txt","r");
char content[1000];
fputs("i love one piece anime
",fptr);
fputs("the most one that i love in one piece is lufy", fptr);
fclose(fptr);
fptr = fopen("one piece.txt","r");
while(fgets(content, 1000, fptr)){
printf("%s",content);
}
return 0;
}
#include
int main() {
FILE* fptr;
fptr = fopen("newFile.txt", "w");
fputs("C is a fun programming language
", fptr);
fputs("And, I love using C language", fptr);
fclose(fptr);
char content[1000];
fptr = fopen("newFile.txt", "r");
if (fptr != NULL) {
while (fgets(content, 1000, fptr)) {
printf("%s", content);
}
}
else {
printf("File Open Unsuccessful");
}
fclose(fptr);
return 0;
}
Option B
B
B. FILE* pointer;
FILE *pointer
b
#include
int main() {
FILE* fptr;
fptr = fopen("newFile.txt", "w");
fputs("C is fun programming language
", fptr);
fputs("And, I love using C programming", fptr);
fclose(fptr);
fptr = fopen("newFile.txt", "r");
char content[1000];
if (fptr != NULL) {
while(fgets(content, 1000, fptr)) {
printf("%s", fptr);
}
}
else {
printf("File open Unsuccessful");
}
fclose(fptr);
return 0;
}
Option B
B
B
B
B
B