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);
   
  }
}   
 
   }

Recommended Answers

All 2 Replies

Aside from beeing formatted poorly and riddled with undefined constructs, what is it not doing that you want it to? Posting a vague question and ugly code isn't likely to get you a useful answer, so you need to work with us if you want help solving your problem.

Hi,
Thanks 4 reply. well i know iam not that good . the problem whcih i have is that the code works file without any function or more source file.
it was only exmaple to see get the idea how the fuction works as i dont know it yet .
example:
with switch cases the code are ok but i need to make it upside down.

from fseek(fp,0,2); until end it was my adding code so . as it is toomany lines and did not want to put it here if it is ok i can posti it to you to see my real problem,

any advice and comment most welcome.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.