
Untitled
By: a guest on
Jun 27th, 2012 | syntax:
None | size: 5.78 KB | hits: 12 | expires: Never
#include <stdio.h>
#include <stdlib.h>
void Menu2();
void Kwadrat(int,int,int,char);
void Prostokat(int,int,int,char);
void Punkt(int,int,int,char);
void Zapisz();
void Wczytaj();
void Wyczysc();
int main()
{
int wybor;
while(1)
{
printf("Co chcesz zrobic?:\n1-Wyrysowac figury na ekranie\n2-Wczytac figure z pliku\n3-Zapisac figure do pliku:\t");
scanf("%d", &wybor);
fflush(stdin);
("cls"); // dla windows
// system("clear"); // dla linuxa
switch(wybor)
{
case 1: Menu2(); break;
case 2: Wczytaj(); break;
case 3: Zapisz(); break;
case 4: Wyczysc(); break;
}
}
}
void Wyczysc()
{
int wybor;
int ile;
int i;
printf("1- Czysci caly ekran\n2-Czysci czesc ekranu:\t");
scanf("%d", &wybor);
fflush(stdin);
if(wybor==1)
{
system("CLS"); // windows
//system("clear"); linux
}
else{
printf("Ile znakow chcesz usunac?\t");
scanf("%d", &ile);
fflush(stdin);
for(i=0; i<ile; i++)
{
putchar('\b');
}
}
}
void Kwadrat(int x, int y, int pelne, char z)
{
FILE *temp;
int i,j,k;
temp=fopen("temp","w+b");
// ustawiamy od ktorego wiersza rysujemy
for(i=0;i<y;i++)
{
printf("\n");
fputc('\n',temp);
}
if(pelne>0)
{
for(i=0;i<8;i++)
{
for(j=0;j<=x;j++)
{
printf(" ");
fputc(' ', temp);
}
for(k=0;k<8;k++){
putchar(z);
fputc(z,temp);
}
putchar('\n');
fputc('\n',temp);
}
}
else
{
for(i=0;i<8;i++)
{
for(j=0;j<=x;j++)
{
printf(" ");
}
if(i==0 || i==7){
putchar(' ');
for(k=0;k<8;k++)
putchar(z);
}
else{
putchar(z);
fputc(z,temp);
for(k=0;k<8;k++){
putchar(' ');
fputc(' ',temp);
}
putchar(z);
fputc(z,temp);
}
putchar('\n');
fputc('\n',temp);
}
}
fclose(temp);
}
void Prostokat(int x, int y, int pelne, char z)
{
FILE *temp;
int i,j,k;
temp=fopen("temp","w+b");
// ustawiamy od ktorego wiersza rysujemy
for(i=0;i<y;i++)
{
printf("\n");
fputc('\n',temp);
}
if(pelne>0)
{
for(i=0;i<5;i++)
{
for(j=0;j<=x;j++)
{
printf(" ");
fputc('\n',temp);
}
for(k=0;k<10;k++){
putchar(z);
fputc(z,temp);
}
putchar('\n');
fputc('\n',temp);
}
}
else
{
for(i=0;i<5;i++)
{
for(j=0;j<=x;j++)
{
printf(" ");
fputc(' ',temp);
}
if(i==0 || i==4){
putchar(' ');
fputc(' ',temp);
for(k=0;k<10;k++)
putchar(z);
fputc(z,temp);
}
else{
putchar(z);
fputc(z,temp);
for(k=0;k<10;k++)
{
putchar(' ');
fputc(' ',temp);
}
fputc(z,temp);
putchar(z);
}
putchar('\n');
fputc('\n',temp);
}
}
fclose(temp);
}
void Punkt(int x, int y, int pelne, char z)
{
FILE *temp;
int i;
temp=fopen("temp","w+b");
for(i=0;i<y;i++)
{
putchar('\n');
fputc('\n',temp);
}
for(i=0;i<x;i++)
{
putchar(' ');
fputc('\n',temp);
}
putchar(z);
fputc(z,temp);
fclose(temp);
}
void Menu2()
{
int wybor;
int x;
int y;
int pelne;
char z;
printf("Podaj wspolrzedna X[spacje]:\t");
scanf("%d",&x);
fflush(stdin);
printf("\nPodaj wspolrzedna Y[wiersze]:\t");
fflush(stdin);
scanf("%d", &y);
printf("Figura ma byc wypelniona? 0-nie 1-tak\t");
scanf("%d", &pelne);
fflush(stdin);
printf("Podaj znak jakim chcesz rysowac:");
fflush(stdin);
scanf("%c",&z);
fflush(stdin);
printf("Co chcesz wyrysowac?\n1.Kwadrat\n2.Prostokat\n3.Punkt na obrazie\n");
scanf("%d", &wybor);
fflush(stdin);
system("CLS");// dla windowsa
// system("clear"); // dla linuxa
// Menu wyboru rysowania
switch(wybor)
{
case 1: Kwadrat(x,y,pelne,z); break;
case 2: Prostokat(x,y,pelne,z); break;
case 3: Punkt(x,y,pelne,z);break;
}
}
void Zapisz()
{
char nazwa[20];
FILE * temp;
char kopiowanie;
char c;
FILE * plik;
if((temp=fopen("temp", "r"))!=NULL)
{
printf("Podaj nazwe pliku:");
fflush(stdin);
gets(nazwa);
plik = fopen(nazwa, "w");
while(!feof(temp)){
fscanf(temp,"%c",&c);
fprintf(plik,"%c",c);
}
fclose(temp);
fclose(plik);
system ("remove temp"); // dla windowsa
//system("rm temp"); // dla linuxa
}
else
{
printf("Nie wyrysowales jeszcze zadnej figury");
}
}
void Wczytaj()
{
char nazwa[255],c;
FILE *plik;
fflush(stdin);
printf("Podaj nazwe pliku:\t");
gets(nazwa);
if((plik=fopen(nazwa, "r"))!=NULL)
while(!feof(plik))
{
c=getc(plik);
if(c!= EOF) {
printf("%c",c);
}
}
}