How to get output for files program in c

+1 vote
asked Nov 21 by (130 points)
if we want to get output for file program, what to do,I am getting directly process finished without outputs

1 Answer

0 votes
answered Nov 24 by (300 points)
#include <stdio.h>

int main()
{
    int i=0;
    char ch[100];
    FILE *fp;
    // write();
    fp=fopen("file_name.txt","r");
    
    // fscanf(fp,"%s",ch);  //string will terminate uf we press space_bar.
    
    fgets(ch,100,fp);       //using fgets() allows us to get whole string.
    
    while(putchar(ch[i])!='\0')
      i++;
    fclose(fp);
    printf("\n\n\t\tread successfully  !!!");
    return 0;
}

change the name of the to which you want to to read

hope it will work !
commented Nov 25 by (100 points)
Is the file "file_name.txt" created and saved in onlinegdb ?  Thanks !
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...