I need help! How to fix my code? My code #include int main(){ char filename[100];//variable to store filename in char line[10000],ch=' ';//input buffers int idx=0; //input of filename printf("\n\tEnter File Name: "); scanf("%s",&filename); FILE *input;//pointer to file if((input = fopen(filename,"r"))){ while(ch != EOF){//until end of file is reached ch = fgetc(input);//read next character if(ch=='\n' || ch==EOF){//if it is a newline character,print the line printf("\t"); int i; for(i=0;i
I need help! How to fix my code?
My code
#include<stdio.h>
int main(){
char filename[100];//variable to store filename in
char line[10000],ch=' ';//input buffers
int idx=0;
//input of filename
printf("\n\tEnter File Name: ");
scanf("%s",&filename);
FILE *input;//pointer to file
if((input = fopen(filename,"r"))){
while(ch != EOF){//until end of file is reached
ch = fgetc(input);//read next character
if(ch=='\n' || ch==EOF){//if it is a newline character,print the line
printf("\t");
int i;
for(i=0;i<idx;i++)
printf("%c",line[i]);
printf("\n");
idx=0;
}
else{//else add the current character to the buffer/array of char
line[idx]=ch;
idx++;
}
}
}
else{
printf("\tThe file can't be open. File does not exits.");
}
fclose(input);//close the file
return 0;
}
I'am using C language Codio!
See in expected result!
Step by step
Solved in 2 steps