Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to get output for files program in c

+1 vote
asked Nov 21, 2019 by Etikala Nikhil (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, 2019 by RAGE MONSTER rocks (570 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, 2019 by t c wu (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.
...