Advertisement
Guest User

Untitled

a guest
Jul 7th, 2012
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. //Reads a file.
  2. //Takes the file path as an argument.
  3. void fileread(char f[]) {
  4.     FILE *file = fopen(f, "r");
  5.     int line = 0;
  6.     int character = 0;
  7.     if (file != NULL) {
  8.         char c;
  9.         while((c = fgetc(file)) != EOF) {
  10.             File[line][character] = c;
  11.             if (c == '\n') {
  12.                 line++;
  13.                 character = 0;
  14.             }
  15.             else {
  16.                 character++;
  17.             }
  18.         }
  19.     fclose(file);
  20.     }
  21.     else {
  22.         printf("Error: No such file.\nStarting without an input file.\n");
  23.     }
  24.     Lines = line++; //Update line count.
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement