Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read a file #1

Open
deepika-rana opened this issue Jul 14, 2020 · 3 comments
Open

Read a file #1

deepika-rana opened this issue Jul 14, 2020 · 3 comments

Comments

@deepika-rana
Copy link
Owner

Write a program to read an existing file.

Test Data :
Input the file name to be opened: test.txt

Expected Output :

The content of the file test.txt is :
This is the content of the file

@deepika-rana
Copy link
Owner Author

Deadline : 15-07-20 11:59 pm

@jahnavi-koduri
Copy link
Contributor

#include<stdio.h>
#include<stdlib.h>
int main()
{
File*fptr;
char ch;
fptr=fopen("test. txt","r");
if(fptr==null)
{
printf("unable to open the file please check the name of the file entered. \n");
Exit(exit_failure);
}
do
{
ch=fgetc(fptr);
putchar(ch);
}
while(ch!=EOF);
fclose(fptr);
return 0;
}

@Michellejacob001
Copy link
Contributor

#include<stdio.h>
test.txt
#include<stdlib.h>

int main() {

FILE *ptr; char c[100];

ptr=fopen("test.txt","r");

if(ptr==NULL) { printf("the file is empty"); exit(1); } printf("enter the data"); fgets(c,sizeof(c),stdin);

fprintf(ptr,"%s",c);
fclose(ptr); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants