Example #1
0
// modify data
void modify(){
  int p,c = 0;
  node *z;
  do {
  printf("\t\tWhat position want to modify (1st = 0 postion) : ");scanf("%d",&p);mfflush();
  if(p  < 0 || p > countList(root)-1) printf("\t\tInvaild location !!\nInput value again !! \n");
  } while(p  < 0 || p > countList(root)-1);
  if(p == 0) z = root;
  else { z = root->next;
    while(z != NULL){
      c++;
      if(c == p) break;
      z = z->next;
    }
  }
  printf("\t\tData of position %d :",p);
  printf("%s %d gb %.2f'' %d VND\n",z->element.model,z->element.size,z->element.screen,z->element.price);

  printf("\t\tWhat you want to modify :");
  if((c = getmenu("Model;Size;Size of screen;Price",4,0)) == 1){
    printf("\t\t %s --> ",z->element.model);scanf("%[^\n]",z->element.model);mfflush();
  } else if(c == 2 ){
    printf("\t\t %d --> ",z->element.size);scanf("%d",&z->element.size);mfflush();
  } else if (c == 3){
    printf("\t\t %f --> ",z->element.screen);scanf("%f",&z->element.screen);mfflush();
  } else{
    printf("\t\t %d --> ",z->element.price);scanf("%d",&z->element.price);mfflush();
  }
  printf("\t\tData of position %d after modifed :",p);
  printf("%s %d gb %.2f'' %d VND\n",z->element.model,z->element.size,z->element.screen,z->element.price);
}
Example #2
0
int main(int argc,char **argv)
{
	char choice[10];
	system("clear");
	getmenu("hello kitty!",menu);
	while(1) 
	{
		printf(">");
		scanf("%s",choice);
		if(strcmp(choice,"q") == 0)
		{	
			printf("quit!\n");
			exit(0);
		}
		printf("%s\n",choice);
	}

	exit(0);
}
Example #3
0
int main(int argc, char *argv[])
{
  FILE *ft,*fd;

  while (1) {
    switch(getmenu("Import DB from NokiaDB.dat;Print data;Insert data;Delete data;Search Data & modify data;Devide list & Extract List;Reverse list;Save to file;Quit",9,0))
      {  mfflush();
      case 1:
        if((fd = fopen(DAT,"r+b")) == NULL) printf("\t\tCan't read file %s",DAT);
        else {
          if(getmenu("Insert Whole;Insert Part",2,0) == 1) {
              importfdat(fd,1,1);
          } else {
            if(getmenu("From Begin;From ending",2,0) == 1) importfdat(fd,2,1);
            else importfdat(fd,2,2);
          }
            printf("\t\tImport DB complete !!\n");
            fclose(fd);
        } break;
      case 2:if(root == NULL && root2 == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          if(root2 == NULL) printdat(root);
          else {
            int c ;
            if((c = getmenu("Print data of first list;Print data of second list",2,0)) == 1)
              printdat(root); else printdat(root2);
          }
        }
        break;
      case 3:if(root == NULL){
          indent(2); printf("Import data first !!\n");
        } else {
          int c;
          VARTYPE p;
          printf("\t\tModel of phone :");scanf("%[^\n]",p.model);mfflush();
          printf("\t\tSize of phone :");scanf("%d",&p.size);mfflush();
          printf("\t\tPhone's size of screen :");scanf("%f",&p.screen);mfflush();
          printf("\t\tPhone's price :");scanf("%d",&p.price);mfflush();
          if((c = getmenu("Insert at Begining;Insert at Ending;Insert at Position",3,0)) == 1) {
            insertB(p);
          } else if (c == 2) insertE(p);
          else {
            int z;
            node *g;
            do {
            printf("\t\t Where you want to insert (if you don't want to insert anymore input -1 !! 1st = 0 postion) :");scanf("%d",&z);mfflush();
            g = insertAtPosition(p,z);
            } while (g == NULL && z != -1);
          }
        }break;
      case 4:if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          int c;
          if((c = getmenu("Delete at Postion;Delete current;Delete first",3,0))==1)  {
            int p;
            printf("\t\t Where you want to delelte (if you don't want to insert anymore input -1 !! 1st = 0 postion) :");scanf("%d",&p);mfflush();
            deleteAtPosition(p);
          } else if(c == 2) delNode(cur);
          else if(c == 3) delNode(root);
        } break;
      case 5:
        if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          int cc;
          if((cc = getmenu("Search data;Modify data",2,0)) == 1){
            int c;
            if((c = getmenu("Search By name;Search By Price",2,0)) ==1)
              search(root,1);
            else search(root,2);
          } else {
            modify();
          }
        } break;
      case 6:
        if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          int c;
          if((c = getmenu("Devide List;Extract list",2,0))==1){
            int p;
            printf("\t\tPostion you want to devide list : ");scanf("%d",&p);mfflush();
            root2 = devideList(root,last,p);
          } else {
            int p,n;
            printf("\t\tPostion you want to start extract list : ");scanf("%d",&p);mfflush();
            printf("\t\tLength of extract list : ");scanf("%d",&n);mfflush();
            extractList(p,n);
          }
        }break;
        case 7:if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          reversel();
        }break;
      case 8:if(root == NULL) {
          indent(2); printf("Import data first !!\n");
        } else {
          if((fd = fopen(DAT,"w+b")) == NULL) printf("Can't create file %s",DAT);
          else {
            exporttdat(fd);
          }
        }break;
      case 9:
        freelist(root);
        freelist(root2);
        indent(2);printf("Exit Program !!\n");
        return 0;
      }
  }
}
Example #4
0
int main(void)
{
	struct planestats plane[SEATS];
	int choice;
	int i;
	size_t size = sizeof(struct planestats);
	FILE *fp;
	
	if((fp = fopen("air.dat","rb")) == NULL)
		{
			fprintf(stderr, "Can't open file %s","air.dat\n");
			if((fp = fopen("air.dat","wb")) == NULL)
				{
					exit(1);
				}
			for(i = 0; i < SEATS; i++)
				{
						plane[i].seat_id = i + 1;
						plane[i].status = 0;
				}	
				
			fwrite(plane, size , SEATS, fp);
			puts("We created the file air.dat now.");
			exit(1);
		}
	
	for(i = 0; i < SEATS; i++)
		{
				plane[i].seat_id = i + 1;
				plane[i].status = 0;
		}
	fread(plane, size , SEATS, fp);
	fclose(fp);
	
	while((choice = getmenu()) != 'f')	
		{
			switch(choice)
			{
				case 'a': printf("%d seat is empty!\n",empty_seat(plane,SEATS));
									break;
				case 'b':	show_empty(plane,SEATS);
									break;
				case 'c':	show_seats(plane,SEATS);
									break;
				case 'd':	assign_seat(plane,SEATS);
									break;
				case 'e':	delet_seat(plane,SEATS);
									break;				
			}	
		}
		
	if((fp = fopen("air.dat","wb")) == NULL)
		{
			fprintf(stderr, "Can't open file %s","air.dat");
			exit(1);
		}	
	fwrite(plane, size , SEATS, fp);
	fclose(fp);	
		
	puts("Bye!");	
			
	return 0;
}