Answer to Question #207195 in C for Imran

Question #207195

Write a program which read characters from keyboard and write in a file until user 

input “enter key” from keyboard.



1
Expert's answer
2021-06-15T07:08:44-0400
#include <stdio.h>


int main(void) {
  FILE *fptr;
  char ch;
  
  // open the file in write mode
  fptr = fopen("username.txt", "w");
  
  // take user input
  printf("Enter your name: ");
  
  // keep reading the user input from the terminal
  // till Return (Enter) key is pressed
  while( (ch = getchar()) != '\n' ) {


    // write character ch in file
    putc(ch, fptr);
  }
  fclose(fptr);
  
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS