LibertyPaul

6lab.mycomm.cxx

May 9th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include "mycomm.h"
  4. int state=0;
  5. int row=0, col=0;
  6. FILE *f;
  7. char area[MAX_ROWS][MAX_COLS];
  8.  
  9.  
  10.  
  11. void reset(){
  12.     for(int i=0;i<MAX_ROWS;i++)
  13.         for(int j=0;j<MAX_COLS;j++)
  14.             area[i][j]=' ';
  15.     row=0, col=0;
  16. }
  17.  
  18. void writefile(){
  19.     f=fopen(fname, "w+");
  20.     for(int i=0;i<MAX_ROWS;i++){
  21.         for(int j=0;j<MAX_COLS;j++)
  22.             fputc(area[i][j], f);
  23.         fputc('\n', f);
  24.     }
  25.     fclose(f);
  26. }
  27.  
  28. void write(){
  29.     if(state){
  30.         area[row][col]=42;
  31.         writefile();
  32.     }
  33. }
  34.  
  35. void move(int d){
  36.     switch (d){
  37.         case 1:col--;break;
  38.         case 2:col++;break;
  39.         case 3:row++;break;
  40.         case 4:row--;break;
  41.         default: break;
  42.     }
  43.     write();
  44. }
  45.  
  46.  
  47.  
  48. void show(){
  49.     char c;
  50.     f=fopen(fname, "r");
  51.     while(!feof(f)){
  52.             c=fgetc(f);
  53.             printf("%c", c);
  54.         }
  55.     getch();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment