Hi, :?: any one please can tell me what iam doing worng ?
what iam trying to do is that to make program to create small database with following option add, delete , show ,edit search but i need to have them in it´s own source code so. what iam trying to do it that to create for each one of them first an function module then ...
now i have no idea what is wrong ??
any help please ?
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void add_autot(void);
struct cee
{
long float vuosi_maali,ajettu,hinta;
char auton_nimi[15],omistaja_nimi[20],maali_dis,ajettu_dis,hinta_dis;
}
s,arr[100],temp;
char nomistaja_nimi[20],nauton_nimi[15];
int choose,i,c,k,flag,ruttu,laskuri;
long int recsize;
FILE *fp;
void main(void)
{
int choose;
do
{
printf("Valitse :\n\n");
printf("1. add car\n");
printf("2 = finito\n\n");
printf("Choose: ");
choose = getche()-'0';
if(choose<0 || choose>2)
{
printf("\nValinnan oltava 1 - 2\n");
}
}while(choose<0 || choose>2);
switch(choose)
{
case 1:
{fflush(stdin);void add_autot(void);}
break;
case 4:
printf("\n Poistutaan ohjelmasta");
}
}
void add_autot(void)
{
recsize=sizeof(s);
fp=fopen("hello.bin","rb+");
if(fp==NULL)
{
fp=fopen("hello.bin","wb+");
if(fp == NULL)
{
printf("\n\nFilukan avaminen ei onnistui");
fseek(fp,0,2);
s.maali_dis=NULL;
s.ajettu_dis=NULL;
s.hinta_dis=NULL;
printf("\n\nAnna Auton Nimi: ");
scanf("%s",s.auton_nimi);
printf("Anna Omistjan Nimi: ");
scanf("%s",s.omistaja_nimi);
printf("Auton Vuosi Maali: ");
scanf("%lf",&s.vuosi_maali);
printf("Auto Ajettu: ");
scanf("%lf",&s.ajettu);
printf("Auton Hinta: ");
scanf("%lf",&s.hinta);
if(s.vuosi_maali == 0)
s.maali_dis='-';
if(s.ajettu == 0)
s.ajettu_dis='-';
if(s.hinta == 0)
s.hinta_dis='-';
fwrite(&s,recsize,1,fp);
i=0;
rewind(fp);
while(fread(&s,recsize,1,fp)==1)
{
arr[i]=s;
i++;
}
for(c=0;c<i-1;c++)
{
for(k=0;k<i-1;k++)
{
if( strcmp(arr[k].omistaja_nimi,arr[k+1].omistaja_nimi) > 0 )
{
temp=arr[k];
arr[k]=arr[k+1];
arr[k+1]=temp;
}
}
}
rewind(fp);
for(k=0;k<i;k++)
fwrite(&arr[k],recsize,1,fp);
}
}
}