Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 5.78 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void Menu2();
  5. void Kwadrat(int,int,int,char);
  6. void Prostokat(int,int,int,char);
  7. void Punkt(int,int,int,char);
  8. void Zapisz();
  9. void Wczytaj();
  10. void Wyczysc();
  11. int main()
  12. {
  13.  
  14.    
  15.     int wybor;
  16.     while(1)
  17.     {
  18.     printf("Co chcesz zrobic?:\n1-Wyrysowac figury na ekranie\n2-Wczytac figure z pliku\n3-Zapisac figure do pliku:\t");
  19.     scanf("%d", &wybor);
  20.     fflush(stdin);
  21.     ("cls"); //    dla windows
  22.    // system("clear"); // dla linuxa
  23.     switch(wybor)
  24.     {
  25.     case 1: Menu2(); break;
  26.     case 2: Wczytaj(); break;
  27.     case 3: Zapisz(); break;
  28.     case 4: Wyczysc(); break;
  29.    
  30.     }
  31.     }
  32. }
  33.  
  34.  
  35. void Wyczysc()
  36. {
  37. int wybor;
  38. int ile;
  39. int i;
  40. printf("1- Czysci caly ekran\n2-Czysci czesc ekranu:\t");
  41. scanf("%d", &wybor);
  42. fflush(stdin);
  43. if(wybor==1)
  44. {
  45.  
  46. system("CLS"); // windows
  47. //system("clear"); linux
  48. }
  49. else{
  50. printf("Ile znakow chcesz usunac?\t");
  51. scanf("%d", &ile);
  52. fflush(stdin);
  53. for(i=0; i<ile; i++)
  54. {
  55.     putchar('\b');
  56. }
  57.  
  58. }
  59. }
  60. void Kwadrat(int x, int y, int pelne, char z)
  61. {
  62.            FILE *temp;
  63.              int i,j,k;
  64.            temp=fopen("temp","w+b");
  65.          
  66.    // ustawiamy od ktorego wiersza rysujemy
  67.         for(i=0;i<y;i++)
  68.         {
  69.             printf("\n");
  70.             fputc('\n',temp);
  71.            
  72.         }
  73.     if(pelne>0)
  74.     {
  75.        
  76.         for(i=0;i<8;i++)
  77.       {
  78.                
  79.         for(j=0;j<=x;j++)
  80.         {
  81.           printf(" ");
  82.           fputc(' ', temp);
  83.         }
  84.                
  85.        for(k=0;k<8;k++){
  86.         putchar(z);
  87.         fputc(z,temp);
  88.         }
  89.         putchar('\n');
  90.         fputc('\n',temp);
  91.       }
  92.     }
  93.    
  94.     else
  95.     {
  96.         for(i=0;i<8;i++)
  97.       {
  98.                
  99.         for(j=0;j<=x;j++)
  100.         {
  101.           printf(" ");          
  102.         }
  103.        
  104.         if(i==0 || i==7){
  105.         putchar(' ');
  106.         for(k=0;k<8;k++)
  107.         putchar(z);
  108.         }
  109.         else{
  110.        
  111.         putchar(z);
  112.         fputc(z,temp);
  113.         for(k=0;k<8;k++){
  114.         putchar(' ');
  115.         fputc(' ',temp);
  116.         }
  117.         putchar(z);
  118.         fputc(z,temp);
  119.          }    
  120.         putchar('\n');
  121.         fputc('\n',temp);    
  122.              }      
  123.    
  124.     }
  125.     fclose(temp);
  126. }
  127.  
  128. void Prostokat(int x, int y, int pelne, char z)
  129. {  
  130.  
  131.             FILE *temp;
  132.            int i,j,k;
  133.            temp=fopen("temp","w+b");
  134.  
  135.    // ustawiamy od ktorego wiersza rysujemy
  136.     for(i=0;i<y;i++)
  137.         {
  138.             printf("\n");
  139.             fputc('\n',temp);    
  140.         }
  141.  
  142.     if(pelne>0)
  143.     {
  144.        
  145.         for(i=0;i<5;i++)
  146.       {
  147.                
  148.         for(j=0;j<=x;j++)
  149.         {
  150.         printf(" ");
  151.         fputc('\n',temp);                      
  152.         }
  153.                
  154.        for(k=0;k<10;k++){
  155.         putchar(z);
  156.         fputc(z,temp);    
  157.         }
  158.         putchar('\n');
  159.         fputc('\n',temp);    
  160.       }
  161.     }
  162.    
  163.    else
  164.     {
  165.         for(i=0;i<5;i++)
  166.       {
  167.                
  168.         for(j=0;j<=x;j++)
  169.         {
  170.           printf(" ");          
  171.         fputc(' ',temp);    
  172.         }
  173.        
  174.         if(i==0 || i==4){
  175.         putchar(' ');
  176.         fputc(' ',temp);    
  177.         for(k=0;k<10;k++)
  178.         putchar(z);
  179.         fputc(z,temp);
  180.         }
  181.         else{
  182.        
  183.         putchar(z);
  184.         fputc(z,temp);
  185.         for(k=0;k<10;k++)
  186.         {
  187.         putchar(' ');
  188.         fputc(' ',temp);
  189.         }
  190.         fputc(z,temp);
  191.         putchar(z);
  192.  
  193.          }    
  194.         putchar('\n');    
  195.         fputc('\n',temp);
  196.              }      
  197.    
  198.     }
  199.         fclose(temp);
  200. }
  201.  
  202.     void Punkt(int x, int y, int pelne, char z)
  203.     {
  204.     FILE *temp;
  205.     int i;
  206.     temp=fopen("temp","w+b");
  207.  
  208.     for(i=0;i<y;i++)
  209.     {
  210.     putchar('\n');
  211.     fputc('\n',temp);
  212.     }
  213.     for(i=0;i<x;i++)
  214.     {
  215.     putchar(' ');
  216.     fputc('\n',temp);
  217.     }
  218.     putchar(z);
  219.     fputc(z,temp);
  220.    
  221.     fclose(temp);
  222.     }
  223.    
  224.    
  225.    
  226.     void Menu2()
  227.   {
  228.  
  229.     int wybor;
  230.     int x;
  231.     int y;
  232.     int pelne;
  233.     char z;
  234.  
  235.     printf("Podaj wspolrzedna X[spacje]:\t");
  236.     scanf("%d",&x);
  237.     fflush(stdin);
  238.     printf("\nPodaj wspolrzedna Y[wiersze]:\t");
  239.     fflush(stdin);
  240.     scanf("%d", &y);
  241.     printf("Figura ma byc wypelniona? 0-nie 1-tak\t");
  242.     scanf("%d", &pelne);
  243.     fflush(stdin);
  244.     printf("Podaj znak jakim chcesz rysowac:");
  245.     fflush(stdin);
  246.     scanf("%c",&z);
  247.     fflush(stdin);
  248.     printf("Co chcesz wyrysowac?\n1.Kwadrat\n2.Prostokat\n3.Punkt na obrazie\n");
  249.     scanf("%d", &wybor);
  250.     fflush(stdin);
  251.     system("CLS");// dla windowsa
  252.    // system("clear"); // dla linuxa
  253.        
  254.         // Menu wyboru rysowania
  255.             switch(wybor)
  256.     {
  257.         case 1: Kwadrat(x,y,pelne,z); break;
  258.         case 2: Prostokat(x,y,pelne,z); break;
  259.         case 3: Punkt(x,y,pelne,z);break;
  260.     }
  261.  
  262.  
  263.   }
  264.  
  265.   void Zapisz()
  266.   {
  267.     char nazwa[20];
  268.     FILE * temp;
  269.     char kopiowanie;
  270.     char c;
  271.     FILE * plik;
  272.     if((temp=fopen("temp", "r"))!=NULL)
  273.     {
  274.    
  275.     printf("Podaj nazwe pliku:");
  276.     fflush(stdin);
  277.     gets(nazwa);
  278.     plik = fopen(nazwa, "w");
  279.  
  280.    
  281.     while(!feof(temp)){
  282.         fscanf(temp,"%c",&c);
  283.         fprintf(plik,"%c",c);
  284.     }
  285.     fclose(temp);
  286.     fclose(plik);
  287.     system ("remove temp"); // dla windowsa
  288.    //system("rm temp"); // dla linuxa
  289.     }
  290.     else
  291.     {
  292.     printf("Nie wyrysowales jeszcze zadnej figury");  
  293.     }
  294.    
  295.   }  
  296.  
  297.   void Wczytaj()
  298.   {
  299.     char nazwa[255],c;
  300.     FILE *plik;
  301.     fflush(stdin);
  302.     printf("Podaj nazwe pliku:\t");
  303.     gets(nazwa);
  304.     if((plik=fopen(nazwa, "r"))!=NULL)
  305.         while(!feof(plik))
  306.         {
  307.                                 c=getc(plik);
  308.                                 if(c!= EOF) {
  309.                                         printf("%c",c);
  310.                                 }
  311.                        
  312.                         }                      
  313.         }