Advertisement
EBobkunov

write_into_file.txt

Mar 10th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main() {
  4.     char s[10001]; // 10k letters, 1 for null char
  5.     // read spaces also in the string (the whole line)
  6.     // no & in scanf before string (char arrays) names
  7.     scanf("%[^\n]", s);
  8.     FILE *f = fopen("file.txt", "w");
  9.     if (f == NULL) {
  10.         printf("Error opening file!\n");
  11.         exit(1);
  12.     }
  13.     fprintf(f, "%s\n", s);
  14.     fclose(f);
  15. }
Tags: file write
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement