All pastes #352351 Raw Edit

Mine

public text v1 · immutable
·published 2007-02-12 19:33 UTC
rendered paste body
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>

#define NUM 49
#define BALLS 6

int i,b,z;
FILE *file;

int rnd(int range);
void seedrnd(void);
void ldraw(int *box);
void locompare(int *tips, int *zahlen);
int getJackpot(void);
void setJackpot(int add);

int main()
{
char arg[128];
int numbers[NUM],*ueber,*numb,tmp[BALLS];
z=0;



  printf("L O T T O   Z I E H U N G \n\n\n");
  b=getJackpot();
  printf("Diese Woche sind ganze %5d $ im Jackpot. Mitmachen lohnt sich!\n",b);
  printf("Wollen Sie einen Tipp abgeben?\n");
  fgets(arg,128,stdin);
  sscanf(arg,"%c",&arg);
  if((int)arg[0]=='j')
	{
	ueber=malloc(sizeof(tmp));
	for (i=0;i<BALLS;i++)
	tmp[i]=0;
 	 printf("Bitte geben Sie ihren Tipp ab. Vorsicht, keine Zahl doppelt!\n");
	  for (i=1;i<BALLS+1;i++)
 	 {   printf("\n%d.te Zahl:",i);
  	     fgets(arg,128,stdin);
  	     z=atoi(arg);
  	     tmp[i-1]=z;
	     ueber[i-1]=z;
 	 }
 	printf("Zur Wiederholung, hier ihr Tipp:");
  	for (i=0;i<BALLS;i++)
  	printf("%d\x20 ",tmp[i]);
	z=1;
}

printf("\n\nDie Zahlen dieser Woche werden gleich gezogen:\n\n");
seedrnd();
printf("Es geht los:");
 for (i=0;i<NUM;i++)
	 numbers[i]=0;
 numb=malloc(sizeof(tmp));
 for (i=0;i<BALLS;i++)
  { do
 	{b=rnd(NUM);
	 numb[i]=b;
	 }
    while(numbers[b-1]);
   numbers[b-1]=1;
   printf(" %2i ",b);
 }
printf("\nViel Erfolg!\n");
if (z==1)
 locompare(ueber,numb);
return 0;
}


int rnd(int range)
{  int r;
   r = rand()%range+1;
   return r;

}

void seedrnd(void)
{   srand((unsigned)time(NULL));
}

void ldraw(int *box)
{  //for (i=0;i< BALLS;i++)
    //printf("%d\x20",tmp[i]);
}

void locompare(int *tip, int *zahlen)
{  int j,tmp2,tmp,count=0;;

  for (i=0;i<BALLS;i++)
  { for (j=0;j<BALLS;j++)
    { if (tip[i]==zahlen[j])
    	{printf("\nTreffer! --> %i\n",tip[i]);
	 count++;
	}
    }
  }
 printf("Sie haben %d Treffer\n",count);
 if (count==0)
 	setJackpot(10);
	else if (count<=2)
		setJackpot(5);
		else if(count<6)
			setJackpot(2);
			else if (count==6)
				printf("VOLLTREFFER!!!!!!!!\n\n");

}

int getJackpot(void)
{
int j,l;
//char buf[16]="";

file=fopen("jackpot.txt","at");
fseek(file,0,SEEK_END);
printf("%d länge der zeile\n",l=ftell(file));
fseek(file,0,SEEK_SET);
fscanf(file,"%i",j);

//j=atoi(buf);

printf("%3d  steht in j\n\n\n",j);
fclose(file);
return j;
}

void setJackpot(int add)
{
int j;

j=getJackpot();
printf("add: %d, j: %d\n",add,j);
j=j+1+add;
file=fopen("jackpot.txt","wt");
fseek(file,0,SEEK_SET);
fprintf(file,"%c",j);

printf("j(neu): %d\n",j);
fclose(file);
}