Пример #1
0
int main(void){
	
	int choice;
	char done;
	printmenu();
	printf("play??\n");
	scanf("%d, &choice");
	if(choice == 2)
		return;
	done =  ' ';
	init_matrix();

	do{
        	display_matrix();
        	player_move();
  		/* see if player is winner */
    		done = check(); 
    		if(done != ' ') 
			break; /* player is winner!*/
    		computer_move();
    		done = check(); /* see if computer is winner */	
	} 
	while(done == ' ');
	if(done == 'X') 
   		printf("-----YOU WON!!!-----\n");
        else{
		printf("-----I WON!!!!-----\n");
		printf("-----OOPS!!! YOU LOSE...TRY NEXT TIME-----\n");
		printmenu();
	}
   		display_matrix(); /* show final positions */

        return 0;
}
int main(int argc, char *argv[]) {
    pid_t pid;
    int command;
    int flag = 1;
    
    pid = fork();
    
    if (pid < 0) {
        printf("fork error\n");
        return -1;
    }
    else if (pid == 0) {
        // child
        notificationReceiver();
    }
    else {
        // father
        printmenu();
        while (flag) {
            scanf("%d", &command);
            switch (command) {
                case 1:
                    
                    break;
                case 2:
                    
                    break;
                case 3:
                    
                    break;
                case 9:
                    if (kill(pid, SIGTERM) < 0) {
                        printf("kill error\n");
                    }
                    else {
                        printf("all terminate\n");
                        flag = 0;
                    }
                    break;
                case 4:
                    
                    break;
                default:
                    printmenu();
                    break;
            }
        }
    }
}
Пример #3
0
static void edit_ok(int msg)
{
	if(item<=envs_local)
	{
	strcpy(myline,envp_local[item-1]);
	if(menu[item].arg)free(menu[item].arg);
	__cprint(INFO_Y,0,INFO_W,0x7,myline);
	edit_cmdline1(myline);
	__cprint(INFO_Y,0,INFO_W,0x70,myline);
	envp_local[item-1]=menu[item].arg=malloc(strlen(myline)+1);
	strcpy(menu[item].arg,myline);
	selectitem();
	}
	else if(item<items_edit) //run
	{
	 if(msg=='e')
	 {
	strcpy(myline,menu[item].arg);
	free(menu[item].arg);
	__cprint(INFO_Y,0,INFO_W,0x7,myline);
	edit_cmdline2(myline);
	menu[item].arg=malloc(strlen(myline)+1);
	strcpy(menu[item].arg,myline);
	__cprint(INFO_Y,0,INFO_W,0x70,expand(menu[item].arg));
	 }
	 else
	 {
	__popdown(POP_Y,POP_X,POP_H,popwidth);
		do_cmd(expand(menu[item].arg));
	__popup(POP_Y,POP_X,POP_H,popwidth);
	printmenu();
	 }
	}
}
Пример #4
0
static int do_ok(int msg)
{
char *cmd;
	__popdown(POP_Y,POP_X,POP_H,popwidth);
	switch(menu[item].type)
	{
	case TYPE_MENU:do_menu(menu[item].arg);break;
	case TYPE_CMD:
    if(ischoice(menu[item].msg)){
	cmd=getChoiceCmd(menu[item].msg);
	if(!cmd)break;
	}
	else
	{
    cmd=getItemCmd(menu[item].msg);
    cmd=getItemCmd(menu[item].msg);
	}
    cmd=expand(cmd);
	if(msg=='e'){strcpy(myline,cmd);do_cmd(edit_cmdline(myline));}
	else do_cmd(cmd);
	break;
	case TYPE_MSG:__msgbox(MSG_Y,MSG_X,MSG_H,MSG_W,menu[item].arg);break;
	case TYPE_EDITMENU:do_editmenu();break;
	}
	__popup(POP_Y,POP_X,POP_H,popwidth);
	printmenu();
return 0;
}
Пример #5
0
void do_menu(struct setupMenu *newmenu)
{
	struct setupMenu *savedmenu = Menu;
	int saveditem = item;
	Menu = newmenu;
	if(!ItemName||!expline||!myline) __console_alloc();
	item = menu[0].dnext;
	popwidth = Menu->width;
	popheight = Menu->height;
	if(!Menu->action||!Menu->action(MBEGIN))
		default_action(MBEGIN);
	setup_flag = 0;
	__popup(menu[0].y,menu[0].x,popheight,popwidth);
	printmenu();

	while(!setup_flag) {
		int msg = getch();
		if(menu[item].action && menu[item].action(msg))continue;
		if(Menu->action && Menu->action(msg))continue;
		default_action(msg);
	}
	__popdown(menu[0].y,menu[0].x,popheight,popwidth);
	if(!Menu->action||!Menu->action(MEND))
		default_action(MEND);
	setup_flag = 0;
	Menu = savedmenu;
	if(Menu){
		popwidth = Menu->width;
		popheight = Menu->height;
	}
	item = saveditem;
}
Пример #6
0
int default_action(int msg)
{
	switch(msg)
	{
	  case NEXT:deselectitem();nextitem();selectitem();break;
	  case PREV:deselectitem();previtem();selectitem();break;
	  case FORW:deselectitem();rightitem();selectitem();break;
	  case BACK:deselectitem();leftitem();selectitem();break;
	  case 'e':
	  case '\n':
	  case '\r':
			do_ok(msg);break;
	  case 0x1b:deselectitem();setup_flag=-1;break;
	  case UPDATE: default_update();break;
	  case UPDATE1: default_update1();break;
	  case TIMER:
	  case CLEAN:
	  	   	printmenu();break;
	  default:
	  if(msg>='1' && msg <= '9')default_digital(msg);
	  else return 0;
	  break;
	}
	return 1;
}
Пример #7
0
void printmenu() {
	int choice, rval = 0, flag = 0, c;
	
	printf("\n\tEnter 1 for reservation(solapur to pune) :\n\t2. reservation(pune to solapur)\n\t3.canellation\n\t4.enquiry\n\t5.Exit");
	printf("Choice : ");
	scanf("%d", &choice);
	switch(choice) {
		case 1:
			rval = mktime1();
			if(rval == 1) 
				book_ticket1(rval);
			else {
				printf("\nEnter 3 for urgent booking:\n");
				scanf("%d", &c);
				if(c == 3) 
					book_ticket1(c);
				else 
					printmenu();
			}
			break;
		case 2:
			flag = mktime2();
			if(flag == 1)
				book_ticket2(flag);
			else {
				printf("\nEnter 3 for urgent booking:\n");
				scanf("%d", &c);
				if(c == 3) 
					book_ticket2(c);
				else 
					printmenu();
			}
			break;
		case 3:
			cancel();
			break;
		case 4:
			enquiry();
			break;  
		case 5:
			exit(1);
		default:
			printf("Not a valid choice");
	}
}
Пример #8
0
static char *
prompt(struct pkginfo *info, int npkgs)
{
	CKMENU	*menup;
	char	*inst;
	char	ans[MAX_INPUT];
	char	header[256];
	char	temp[256];
	int	i;
	int	n;

	if (maxinst > npkgs) {
		/*
		 * the user may choose to install a completely new
		 * instance of this package
		 */
		n = ckyorn(ans, NULL, NULL, MSG_GETINST_HELP1,
			MSG_GETINST_PROMPT1);
		if (n != 0) {
			quit(n);
		}
		if (strchr("yY", *ans) != NULL) {
			return ("new");
		}
	}

	(void) snprintf(header, sizeof (header), MSG_GETINST_HEADER, pkgabrv);
	menup = allocmenu(header, CKALPHA);

	for (i = 0; i < npkgs; i++) {
		(void) snprintf(temp, sizeof (temp),
				"%s %s\n(%s) %s", info[i].pkginst,
			info[i].name, info[i].arch, info[i].version);
		if (setitem(menup, temp)) {
			progerr("no memory");
			quit(99);
		}
	}

	if (npkgs == 1) {
		printmenu(menup);
		if (n = ckyorn(ans, NULL, NULL, NULL, MSG_GETINST_PROMPT0))
			quit(n);
		if (strchr("yY", *ans) == NULL)
			quit(3);
		(void) strcpy(newinst, info[0].pkginst);
	} else {
		if (n = ckitem(menup, &inst, 1, NULL, NULL, MSG_GETINST_HELP2,
		    MSG_GETINST_PROMPT2))
			quit(n);
		(void) strcpy(newinst, inst);
	}
	(void) setitem(menup, 0); /* clear resource usage */
	free(menup); /* clear resource usage */

	return (newinst);
}
Пример #9
0
int runCommands(heap *hp, bool print)
{
	CmdFunc *commands = createCmdMap();
	if(print)
		printmenu();
	for(int i = 0;; i++) {
		if(print)
			printf(">> ");
		char cmd = readCmd();
		if(commands[(int)cmd])
			commands[(int)cmd](hp, print);
	}
	free(commands);
}
Пример #10
0
Файл: fhdr.c Проект: ombt/ombt
void
editfhdr(ElfObject &eo, char *)
{
	char s[BUFSIZ];

	// start of file headers editing
	printf("editing file headers:\n");

	// start interactive loop
	for (int done=0; !done; )
	{
		// get cmd from user
		printf("fhdr cmd: ");
		rmvnlgets(s);
		tokenize(s, " \t");
		char *pt = gettoken(1);

		// what is the command
		if (pt == NULL || *pt == '\0')
		{
			review(eo);
		}
		else if (*pt == '?' || *pt == 'h')
		{
			printmenu();
		}
		else if (*pt == 'r')
		{
			review(eo);
		}
		else if (*pt == 'u')
		{
			update(eo);
		}
		else if (*pt == 'q')
		{
			done = 1;
		}
		else
		{
			printf("unknown cmd.\n");
		}
	}
	return;
}
Пример #11
0
static int editmenu_action(int msg)
{
	switch(msg)
	{
	  case 'e':
	  case '\n':
	  case '\r':
			edit_ok(msg);break;
	  case 0x1b:deselectitem();quit_edit('\n');break;
	  case UPDATE: edit_update();break;
	  case UPDATE1: edit_update1();break;
	  case CLEAN:
	  	   	printmenu();break;
	  default:
	  if(msg>='1' && msg <= '9')edit_digital(msg);
	  else	return 0;break;
	}
	return 1;
}
Пример #12
0
int main(){
    int index, i;

    for (i = 0; i < 26; i++){
        var[i] = 0;
    }

    printmenu();

    char line[MAXOP], word[MAXOP];
    while (1){
         getLine(line, MAXVAL);

        index = 0;
        while(index != -1){
            index = getword(line, index, word);
            runword(word);
        }
   
    }
   
    return 0; 
}
Пример #13
0
int main(){

    printmenu();

    int type;
    double op2;
    char s[MAXOP];
    while ((type = getop(s)) != END) {
        switch (type) {
        case NUMBER:
            push(atof(s));
            break;

        case '+':
            if (sp > 1){
                push(pop() + pop());
            }

            else printf("Cannot add. Not enough elemnts in stack ;n; \n");

            break;

        case '*':
            if (sp > 1){
                push(pop() * pop());
            }

            else printf("Cannot multiply. Not enough elements in stack ;n; \n");
            break;

        case '-':
            if (sp > 1){
                op2 = pop();
                push(pop() - op2);
            }

            else printf("Cannot subtract. Not enough elements in stack ;n; \n");
            break;

        case '/':
            if (sp > 1){
                op2 = pop();
                if (op2 != 0.0)
                    push(pop() / op2);
                else printf("error: zero divisor ;n;\n");
            }

            else printf("Cannot divide. Not enough elements in stack ;n; \n");
            break;

        case '%':
            if (sp > 1){
                op2 = pop();
                if (op2 != 0.0)
                    push((int)(pop()) % (int)(op2));
                else printf("error:remainder by zero is undefined ;n;\n");
            }

            else printf("Cannot get remainder. Not enough elements in stack ;n;\n");
            break;

        case 'p':
            print();
            break;

        case 'd':    
            duplicate();
            break;

        case 's':
            swap();
            break;

        case 'c':
            printf("clearing stack \n");
            clear();
            break;

        case '\n':
            printlast();
            break;

        case 'm':
            printmenu();
            break;

        default:
            printf("error: unknown command ;n; %s\n", s);
            break; 
        }
    }
    return 0; 
}
Пример #14
0
/* Handle one menu */
pt_menuitem getmenuoption( pt_menu menu, char top, char left, char startopt)
     // Return item chosen or NULL if ESC was hit.
{
  int curr,i;
  char asc,scan;
  char numitems;
  pt_menuitem ci; // Current item
    
  calc_visible(menu);
  numitems = menu->numvisible;
  // Setup status line
  gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
  cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage);

  // Initialise current menu item    
  curr = next_visible(menu,startopt);

  gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
  cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,1);
  gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
  printmenuitem(menu->items[curr]->status,ms->statusattr);
  while (1) // Forever
    {
      printmenu(menu,curr,top,left);
      ci = menu->items[curr];
      asc = getch(&scan);
      switch (scan)
        {
	case HOMEKEY:
	  curr = next_visible(menu,0);
	  break;
	case ENDKEY:
	  curr = prev_visible(menu,numitems-1);
	  break;
	case PAGEDN:
	  for (i=0; i < 5; i++) curr = next_visible(menu,curr+1);
	  break;
	case PAGEUP:
	  for (i=0; i < 5; i++) curr = prev_visible(menu,curr-1);
	  break;
	case UPARROW:
	  curr = prev_visible(menu,curr-1);
	  break;
	case DNARROW:
	  curr = next_visible(menu,curr+1);
	  break;
	case LTARROW:
	case ESCAPE:
	  return NULL;
	  break;
	case RTARROW:
	case ENTERA:
	case ENTERB:
	  if (ci->action == OPT_INACTIVE) break;
	  if (ci->action == OPT_CHECKBOX) break;
	  if (ci->action == OPT_SEP) break;
	  if (ci->action == OPT_EXITMENU) return NULL; // As if we hit Esc
	  return ci;
	  break;
	case SPACEKEY:
	  if (ci->action != OPT_CHECKBOX) break;
	  ci->itemdata.checked = !ci->itemdata.checked;
	  // Call handler to see it anything needs to be done
	  if (ci->handler != NULL) ci->handler(ms,ci); 
	  break;
	default:
	  // Check if this is a shortcut key
	  if (((asc >= 'A') && (asc <= 'Z')) ||
	      ((asc >= 'a') && (asc <= 'z')) ||
	      ((asc >= '0') && (asc <= '9')))
	    curr = find_shortcut(menu,asc,curr);
	  break;
        }
      // Update status line
      gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
      cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage);
      printmenuitem(menu->items[curr]->status,ms->statusattr);
    }
  return NULL; // Should never come here
}
Пример #15
0
void runword (char word[]){
    double op2;
    enum command type = getop(word);
     switch (type) {
     case NUMBER:
        push(atof(word));
        break;

    case PLUS:
        if (sp > 1){
            push(pop() + pop());
        }

        else printf("Cannot add. Not enough elemnts in stack ;n; \n");

        break;

    case MUL:
        if (sp > 1){
            push(pop() * pop());
        }

        else printf("Cannot multiply. Not enough elements in stack ;n; \n");
        break;

    case MIN:
        if (sp > 1){
            op2 = pop();
            push(pop() - op2);
        }

        else printf("Cannot subtract. Not enough elements in stack ;n; \n");
        break;

    case DIV:
        if (sp > 1){
            op2 = pop();
            if (op2 != 0.0)
                push(pop() / op2);
            else printf("error: zero divisor ;n;\n");
        }

        else printf("Cannot divide. Not enough elements in stack ;n; \n");
        break;

    case MOD:
        if (sp > 1){
            op2 = pop();
            if (op2 != 0.0)
                push((int)(pop()) % (int)(op2));
            else printf("error:remainder by zero is undefined ;n;\n");
        }

        else printf("Cannot get remainder. Not enough elements in stack ;n;\n");
        break;

    case PRINT:
        print();
        break;

    case DUP:    
        duplicate();
        break;

    case SWAP:
        swap();
        break;

    case CLEAR:
        printf("clearing stack \n");
        clear();
        break;

    case SIN:
        push(sin(pop()));
        break;

    case COS:
        push(cos(pop()));
        break;

    case TAN:
        push(tan(pop()));
        break;

    case EXP:
        push(exp(pop()));
        break;

    case POW:
        op2 = pop();
        push(pow(op2, pop()));
        break;

    case NEWLINE:
        putlast();
        break;

    case MENU:
        printmenu();
        break;

    case PUTVAR:
        op2 = pop();
        var[word[4]-'a'] = op2;
        printf("setting the variable %c to value %f \n", (word[4]), op2);
        push(op2);
        break;

    case GETVAR:
        push(var[word[0]-'a']);
        break;


    default:
        printf("error: unknown command ;n; %s\n", word);
        break; 
    }
     
}
int main(int argc, char *argv[]) {
    pid_t pid;
    int command;
    int flag = 1;
        
    pid = fork();
    
    if (pid < 0) {
        printf("fork error\n");
        return -1;
    }
    else if (pid == 0) {
        // child
        notificationReceiver();
    }
    else {
        // father
        fileList_root = NULL;
        tail = fileList_root;
        
        protectfd = open(PROC_PROTECT, O_RDWR);
        ctrlfd = open(PROC_NOTI, O_RDWR);
        notifd = open(PROC_NOTI, O_RDWR);
        
        if (protectfd < 0 || ctrlfd < 0 || notifd < 0) {
            printf("open file error!\n");
            exitall();
            return -1;
        }

        printmenu();
        while (flag) {
            scanf("%d", &command);
            switch (command) {
                case 1:
                    printFileList();
                    break;
                case 2:
                    addFile();
                    break;
                case 3:
                    
                    break;
                case 9:
                    if (kill(pid, SIGTERM) < 0) {
                        printf("kill error\n");
                    }
                    else {
                        exitall();
                        flag = 0;
                    }
                    break;
                case 4:
                    
                    break;
                default:
                    printmenu();
                    break;
            }
        }
    }
}
Пример #17
0
void
overwriter(ElfObject &eo, char *)
{
	char s[BUFSIZ];

	// start of overwriter
	printf("section/segment overwriter:\n");

	// start interactive loop
	for (int done=0; !done; )
	{
		// get cmd from user
		printf("overwriter cmd: ");
		rmvnlgets(s);
		tokenize(s, " \t");
		char *pt = gettoken(1);

		// what is the command
		if (pt == NULL)
		{
			printf("unknown cmd.\n");
		}
		else if (*pt == '?' || *pt == 'h')
		{
			printmenu();
		}
		else if (strcmp(pt, "s") == 0)
		{
			// show section data
			printf("section data:\n");
			for (int sec=0; sec<eo.pehdr()->e_shnum; sec++)
			{
				printf("section %d: %s (%ld, %ld)\n", sec, 
					eo.shdrnm(sec),
					eo.pshdr(sec).sh_offset, 
					eo.pshdr(sec).sh_size);
			}
		}
		else if (strcmp(pt, "p") == 0)
		{
			// show section data
			printf("program data:\n");
			for (int seg=0; seg<eo.pehdr()->e_phnum; seg++)
			{
				printf("segment %d: (0x%lx, 0x%lx, %ld)\n", 
					seg, eo.pphdr(seg).p_vaddr, 
					eo.pphdr(seg).p_paddr,
					eo.pphdr(seg).p_memsz);
			}
		}
		else if (strcmp(pt, "po") == 0)
		{
			// get address
			pt = gettoken(2);
			MustBeTrue(pt != NULL && *pt != '\0');
			long addr = MYatoi(pt);
			poverwriter(eo, addr);
		}
		else if (strcmp(pt, "so") == 0)
		{
			// get tokens 
			char *pt2 = gettoken(2);
			char *pt3 = gettoken(3);

			// check if a section was given 
			if (pt2 != NULL && pt3 != NULL)
			{
				long offset = 0;

				// get section
				if (strspn(pt2, "0123456789") == strlen(pt2))
				{
					// section number was given
					int csec = MYatoi(pt2);
					if (csec < 0 || 
					    csec >= eo.pehdr()->e_shnum)
					{
						printf("out-of-range section number.\n");
						printf("minimum section number = 0\n");
						printf("maximum section number = %d\n",
							eo.pehdr()->e_shnum);
						return;
					}
					offset = eo.pshdr(csec).sh_offset;
				}
				else
				{
					// section name was given
					int csec = nametosec(eo, pt2);
					if (csec == NOTOK)
					{
						printf("section not found.\n");
						return;
					}
					offset = eo.pshdr(csec).sh_offset;
				}

				// add relative offset to section offset
				MustBeTrue(pt3 != NULL && *pt3 != '\0');
				offset += MYatoi(pt3);
				soverwriter(eo, offset);
			}
			else if (pt2 != NULL && pt3 == NULL)
			{
				// no section was given, get offset
				MustBeTrue(pt2 != NULL && *pt2 != '\0');
				long offset = MYatoi(pt2);
				soverwriter(eo, offset);
			}
			else
				MustBeTrue(pt2 != NULL || pt3 != NULL);
			
		}
		else if (*pt == 'q')
		{
			done = 1;
		}
		else
		{
			printf("unknown cmd.\n");
		}
	}
	return;
}
Пример #18
0
int main(int argc, char *argv[]) {
	int i, s;
	list q;
	list1 q1;
	list2 q2;
	record d;
	personal f;
	record *ptr, *pt;
	personal *ptr2, *pt2;
	FILE *fp, *fp1, *fp2, *fp3, *fp4, *fp6, *fp8, *fp9, *fp10;
	fp1 = fopen("b.txt", "a+");
	node2 *st2;
	init(&q);
	init1(&q1);
	init2(&q2);
	char a[48];
	char br[32];
	int m, posi, choice, roll, size, s1, s2, s3, s4, num, posii, yr, MIS;
	while(1) {
		choice = printmenu();
		switch(choice) {
			case 1 :
				printf("\nEnter the Name, MIS, Branch, Year of student and the MIS before which you wish to insert the record :\n");  /*if it is the first record 'posi' can be anything*/
				scanf(" %[^\n]%d%s%d%d", a, &m, br, &yr, &posi);
				fp = fopen("k.txt", "a+");
				Add_academic(&q, a, m, br, posi, yr, fp);
				fclose(fp);
				print(&q);
				break;
			case 2 :
				printf("Enter the MIS of the student record to be deleted :\n");
				scanf("%d", &posii);
				fp = fopen("k.txt", "a+");
				fp4 = fopen("d.txt", "w+");
				if(pt = delet_academic(&q, posii,fp,fp4)) {
					printf("Name:%s\n MIS:%d\n Branch:%s\n Year :%d\n", pt->name, pt->MIS, pt->branch, pt->year);
				}
				else {
					printf("INVALID ENTRY\n");
				}
				print(&q);
				fclose(fp);
				fclose(fp4);
				break;
			case 3 :
				printf("Enter the MIS of student :\n");
				scanf("%d", &roll);
				if(ptr = search(&q, roll)) {

					printf("\nName :%s\tMIS :%d\tBranch :%s\tYear :%d\n", ptr->name, ptr->MIS, ptr->branch, ptr->year);

				}
				else {

					printf("\nRECORD NOT FOUND\n");
				}
				break;
			case 4 :
				printf("Enter the Name, MIS, Branch, Year of student :\n");
				scanf(" %[^\n]%d%s%d", a, &m, br, &yr);
				fp = fopen("k.txt", "a+");
				append_academic(&q, a, m, br, yr, fp);
				print(&q);
				fclose(fp);
				break;
			case 5 :
				size = length(&q);
				printf("Number of student records(academic) : %d\n", size);
				break;
			case 6 :
				printf("Enter the MIS of student :\n");
				scanf("%d", &roll);
				creatingID(&q, roll);
				break;
			case 7 :
				fp = fopen("k.txt", "a+");
				fp3 = fopen("a.txt", "r");
				academicfromfile(&q, fp3, fp);
				print(&q);
				fclose(fp);
				fclose(fp3);
				break;
			case 8 :
				printf("Enter the Name, MIS, Branch and Year of student:\n");
				scanf(" %[^\n]%d%s%d", a, &m, br, &yr);  /*MIS should be same*/
				fp = fopen("k.txt", "a+");
				fp6 = fopen("n.txt", "w+");
				Modify_academic(&q, m, a, br, yr, fp, fp6); 
				print(&q);
				fclose(fp);
				fclose(fp6);
				break;
			case 9 :
				num = length1(&q1);
				printf("No of students who appeared for final exam : %d\n", num);
				break;
			case 10 :
				printf("Enter MIS, T1 marks of 4 subjects ,MIS before which you wish to enter the record and the semester :\n");
				scanf("%d%d%d%d%d%d%d",&roll,&s1,&s2,&s3,&s4,&m, &i);
				T1Marks(&q1,roll,s1,s2,s3,s4,m,i); 
				printT1(&q1, i);
				break;	
			case 11 :
				printf("Enter MIS and T2 marks of 4 subjects and the semester :\n");
				scanf("%d%d%d%d%d%d",&roll,&s1,&s2,&s3,&s4, &i);
				T2Marks(&q1,roll,s1,s2,s3,s4,i);
				printT2(&q1, i);
				break;
			case 12 :
				printf("Enter MIS and ESE marks of 4 subjects and the semester :\n");
				scanf("%d%d%d%d%d%d",&roll,&s1,&s2,&s3,&s4,&i);
				ESEMarks(&q1,roll,s1,s2,s3,s4,i);
				printESE(&q1, i);
				break;
			case 13 :
				printf("Enter the MIS and the semester :\n");
				scanf("%d%d", &MIS, &i);
				Total(&q1, MIS,i, fp1);
				printTOT(&q1, i);
				break;
			case 14 :
				printf("Enter the Name, MIS, Mobile no., Email Id of student and the MIS before which you wish to insert the record :\n");  /*if it is the first record, posi can be anything*/
				scanf(" %[^\n]%d%d%s%d", a, &m, &yr, br, &posi);
				fp2 = fopen("c.txt", "a+");
				Add2_personal(&q2, a, m, yr, br, posi, fp2);
				print2(&q2);
				fclose(fp2);
				break;
			case 15 : 
				printf("Enter the MIS of the student record to be deleted :\n");
				scanf("%d", &posii);
				fp2 = fopen("c.txt", "a+");
				fp9 = fopen("s.txt", "w+");
				if(pt2 = delet2_personal(&q2, posii,fp2, fp9)) {
					printf("Name:%s\n MIS:%d\n Mobile No:%d\n Email Id :%s\n", pt2->name, pt2->MISS, pt2->mobile, pt2->email_Id);
				}
				else {
					printf("INVALID ENTRY\n");
				}
				print2(&q2);
				fclose(fp2);
				fclose(fp9);
				break;
			case 16 :
				printf("Enter the MIS of student :\n");
				scanf("%d", &roll);
				if(ptr2 = search2(&q2, roll)) {

					printf("\nName :%s\tMIS :%d\tMobile No :%d\tEmail Id :%s\n", ptr2->name, ptr2->MISS, ptr2->mobile, ptr2->email_Id);
				}
				else {

					printf("\nRECORD NOT FOUND\n");
				}
				break;	
			case 17 :
				printf("Enter the Name, MIS, Mobile no. and Email Id of student:\n");
				scanf(" %[^\n]%d%d%s", a, &m, &yr, br);  /*MIS should be same*/
				fp8 = fopen("w.txt", "w+");
				fp2 = fopen("c.txt", "a+");
				Modify2_personal(&q2, m, a, yr, br,fp2, fp8);
				print2(&q2);
				fclose(fp2);
				fclose(fp8);
				break;
			case 18 :
				printf("\nEnter the MIS of the student and the semester :\n");
				scanf("%d%d", &m, &s);
				link(&q, &q1, &q2, m, s);
				break;
			case 19 :
				fp2 = fopen("c.txt", "a+");
				fp10 = fopen("p.txt", "r");
				personalfromfile(&q2, fp10, fp2);
				print2(&q2);
				fclose(fp2);
				fclose(fp10);
				break;
			case 20 :
				fclose(fp1);
				exit(1);
				break;
		}
	}
}
Пример #19
0
int main(){
    int i, j;

    for (i = 0; i < 26; i++){
        var[i] = 0;
    }

    printmenu();

    enum command type;
    double op2, index;
    char s[MAXOP];
    while ((type = getop(s)) != ENDNUM) {
        switch (type) {
        case NUMBER:
            push(atof(s));
            break;

        case PLUS:
            if (sp > 1){
                push(pop() + pop());
            }

            else printf("Cannot add. Not enough elemnts in stack ;n; \n");

            break;

        case MUL:
            if (sp > 1){
                push(pop() * pop());
            }

            else printf("Cannot multiply. Not enough elements in stack ;n; \n");
            break;

        case MIN:
            if (sp > 1){
                op2 = pop();
                push(pop() - op2);
            }

            else printf("Cannot subtract. Not enough elements in stack ;n; \n");
            break;

        case DIV:
            if (sp > 1){
                op2 = pop();
                if (op2 != 0.0)
                    push(pop() / op2);
                else printf("error: zero divisor ;n;\n");
            }

            else printf("Cannot divide. Not enough elements in stack ;n; \n");
            break;

        case MOD:
            if (sp > 1){
                op2 = pop();
                if (op2 != 0.0)
                    push((int)(pop()) % (int)(op2));
                else printf("error:remainder by zero is undefined ;n;\n");
            }

            else printf("Cannot get remainder. Not enough elements in stack ;n;\n");
            break;

        case PRINT:
            print();
            break;

        case DUP:    
            duplicate();
            break;

        case SWAP:
            swap();
            break;

        case CLEAR:
            printf("clearing stack \n");
            clear();
            break;

        case SIN:
            push(sin(pop()));
            break;

        case COS:
            push(cos(pop()));
            break;

        case TAN:
            push(tan(pop()));
            break;

        case EXP:
            push(exp(pop()));
            break;

        case POW:
            op2 = pop();
            push(pow(op2, pop()));
            break;

        case NEWLINE:
            putlast();
            break;

        case MENU:
            printmenu();
            break;

        case PUTVAR:
            op2 = pop();
            var[s[4]-'a'] = op2;
            printf("setting the variable %c to value %f \n", (s[4]), op2);
            push(op2);
            break;

        case GETVAR:
            push(var[s[0]-'a']);
            break;


        default:
            printf("error: unknown command ;n; %s\n", s);
            break; 
        }
    }
    return 0; 
}
Пример #20
0
Файл: hash.c Проект: ombt/ombt
void
edithash(ElfObject &eo, char *)
{
	char s[BUFSIZ];

	// start of hash table editing
	printf("editing hash tables:\n");

	// initialize hash table pointers
	int csec = eo.pehdr()->e_shnum;
	int cbucket = 0;
	int cchain = 0;

	// find the first hash table
	for (int sec=0; sec<eo.pehdr()->e_shnum; sec++)
	{
		if (eo.pshdr(sec).sh_type == SHT_HASH)
		{
			csec = sec;
			break;
		}
	}
	if (csec >= eo.pehdr()->e_shnum)
	{
		printf("no hash tables found.\n");
		return;
	}
	cchain = EOSWABIT(eo, eo.phashtbls(csec)[cbucket+2]);

	// pointers to hash tables
	Elf32_Word *p0 = eo.phashtbls(csec);
	Elf32_Word *pe = eo.phashtbls(csec) + 
		eo.pshdr(csec).sh_size/sizeof(Elf32_Word);

	// start interactive loop
	for (int done=0; !done; )
	{
		// get cmd from user
		printf("hash cmd: ");
		rmvnlgets(s);
		tokenize(s, " \t");
		char *pt = gettoken(1);

		// what is the command
		if (pt == NULL || *pt == '\0')
		{
			increment(eo, cchain, cbucket, csec, p0, pe);
		}
		else if (*pt == 'n')
		{
			// show all section names
			printf("hash table names:\n");
			for (int sec=0; sec<eo.pehdr()->e_shnum; sec++)
			{
				if (eo.pshdr(sec).sh_type != SHT_HASH)
					continue;
				printf("section %d: %s (%d) nb: %ld, nch: %ld\n", 
					sec, eo.shdrnm(sec), 
					eo.pshdr(sec).sh_name,
					EOSWABIT(eo, eo.phashtbls(sec)[0]), 
					EOSWABIT(eo, eo.phashtbls(sec)[1]));
			}
		}
		else if (*pt == '?' || *pt == 'h')
		{
			printmenu();
		}
		else if (*pt == 'D')
		{
			dflag = !dflag;
			if (dflag)
				printf("demangle mode ON.\n");
			else
				printf("demangle mode OFF.\n");
		}
		else if (*pt == 'r')
		{
			review(eo, cchain, cbucket, csec, p0, pe);
		}
		else if (*pt == 'u')
		{
			update(eo, cchain, cbucket, csec, p0, pe);
		}
		else if (*pt == '+')
		{
			increment(eo, cchain, cbucket, csec, p0, pe);
		}
		else if (*pt == 'q')
		{
			done = 1;
		}
		else
		{
			printf("unknown cmd.\n");
		}

	}
	return;
}
Пример #21
0
void modify(list *l) {

    int i, test = 0, acc;
    int choice, main_exit;
    node *p;
    p = (node *)malloc(sizeof(node));
    node *add, *upd, *check;
    check = l->head;
    printf("\nEnter the account no. of the customer whose info you want to change:");
    scanf("%d",&acc);

    while(check != NULL) {
        if (acc == check->acc_no) {
            printf("**********Account Status**************\n");
            printf("Account number = %d\n",check->acc_no);
            printf("Account holder = %s\n",check->name);
            printf("Type of account = %s\n",check->acc_type);
            printf("Balance amount = %f\n\n\n",check->amt);
            test = 1;
            printf("\nWhich information do you want to change?\n1.Address\n2.Phone\n\nEnter your choice(1 for address and 2 for phone):");
            scanf("%d",&choice);
            if(choice == 1) {
                printf("Enter the new address:");
                scanf("%s",check -> address);
                printf("Changes saved!");
            }
            else if(choice == 2) {
                printf("Enter the new phone number:");
                scanf("%lf",&check -> phone);
                printf("Changes saved!");
            }

            break;
        }
        check = check->next;
    }
    if(test != 1) {

        printf("\nRecord not found!!\a\a\a");
        printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
        scanf("%d",&main_exit);

        if (main_exit==1) {
            printmenu();
        }
        else if (main_exit==2) {
            close();
        }
        else if(main_exit==0) {
            modify(l);
        }
        else {
            printf("\nInvalid!\a");
        }
    }
    else {
        printf("\n\n\nEnter 1 to go to the main menu and 0 to exit:");
        scanf("%d",&main_exit);
        if (main_exit == 1) {
            menuchoice();
        }
        else {
            close();
        }
    }

}
Пример #22
0
void easy()
{
    int i, x, y,key;
    char press[2];
    if(load==false)
        initial(9);
    else
        load=false;
    do {
start:
        printmenu();
        i=0;
        for(y=8; y<17; y+=4)
            for(x=33; x<44; x+=5)
            {
                draw(x,y,i);
                i++;
            }
        userwin(8);
        if(win==true)
        {   cleardevice();
            outtextxy(2,2,"You have won the game");
            delay(2000);
            disp();
            delay(2000);
            win=false;
            return;
        }
        gotoxy (55,17);
        printf("Tips:");
        gotoxy (61,18);
        printf("Number will move");
        gotoxy (61,19);
        printf("when you key in!");
        gotoxy (43,23);
        fflush(stdin);
        press[0]=toupper(getche());
        if(press[0]=='X')
        {
            disp();
            exit(1);
        }
        key=atoi(press);
        if((check(key))==0)
        {
            goto start;
        }
        step++;
        if(step==50)
        {
            cleardevice();
            outtextxy(20,200,"YOU HAVE SURPASSED MAXIMUM POSSIBLE MOVES");
            delay(1500);
            disp();
            delay(2500);
            exit(1);
        }
        for(i=0; i<9; i++)
        {
            if(num[i]==key)
                num[i]=0;
            else if(num[i]==0)
                num[i]=key;
        }
    } while(1);
}
Пример #23
0
SHORT menu_print(void) { printmenu(); }
Пример #24
0
int main(){
	int i,count=0;
	float a[size], *p;
	printmenu();
	printf("enter the choice");
	while(scanf("%d",&i))
		switch(i){
		case 1:	printf("enter the nos");
			while(scanf("%f",&a[count])){
				count++;}
			*p = a[0];
			printmenu();
			break;			
		case 2: printf("mean is %f ",mean(p,count));
			printmenu();
			break;
		case 3:printf("median is %f",median(p,count));
			printmenu();
			break;
		case 4:printf("mode is %f",mode(p,count));
			printmenu();
			break;
		case 5: printf("firstquartile is %f",firstquartile(p,count));
			printmenu();
			break;
		case 6: printf("thirdquartile is %f",thirdquartile(p,count));
			printmenu();
			break;
		case 7: printf("quartile range is %f",quartilerange(p,count));
			printmenu();
			break;
		case 8: printf("range is %f ",findrange(p,count));
			printmenu();
			break;
		case 9: printf("variance is %f ",variance(p,count));
			printmenu();
			break;
		case 10: printf("standard deviation is %f ",mean(p,count));
			printmenu();
			break;
		/*case 11: printf("sorted data is : ");
			for (i = 1;i< count ;i++){
				printf("%f",p[i]);
			printmenu();
			break;*/
		case 12: printf("skewness is %f",skewness(p,count));
				printmenu();
				break;
		case 13:printf("kurtosis is %f",kurtois(p,count));
				printmenu();
				break;
		case 14: p =(float*) NULL;
			count = 0;
			break;
		case 15 : 
			return 0;
}
}
Пример #25
0
int main() {
	
	list k;
	int choice;
	init(&k);/*initializing link list*/	
	while(1) {
		printf("\n\n\tno of buses = %d \n", length(&k));
		choice = printmenu();
		switch(choice) {
		
		case 1: /*adding new bus*/
			fnPrintLine();
			printf("\n\n................................................................................."); 				aaa: printf("\n\t\tplease enter admine passward");
			int pass;
			scanf("%d", &pass);
			if(pass == 1234){

				printf("\n\t\tWelcome\n\n\t");
				Bus *h;
				Bus g;
				g = fnNew_Bus();
				fnEmpty(&g);
				h = &g;
				newbus(&k, h);
				h = NULL;
			}
			
			else {
				printf("Invalid Passward !!!");
				goto aaa;
			}
			
			int a;
			printf("\n\nDo you wan't to continue ? If yes then press 1 ");
			scanf("%d", &a);
			
			if(a == 1){
		 		goto aaa;
				fnPrintLine();
				break;
			}
				
			else{
				fnPrintLine();
				break;
			}
				
		case 2: /*showing available buses*/
			fnPrintLine();
			printf("\n\n................................................................................."); 
			bbb: printf("\n\n\t\tWelcome\n\n\t");
			showbus(&k);
			int b;
			printf("\n\t\tDo you wan't to continue ? If yes then press 1 ");
			scanf("%d", &b);
			if(b == 1) {
				goto bbb;
				fnPrintLine();
				break;		
			}

			else{
				fnPrintLine();
				break;	
			}
	
		case 3: /*ticket booking*/
			fnPrintLine();
			printf("\n\n................................................................................."); 
			printf("\n\n\t\tWelcome");
			ddd: printf("\n\n\t\tEnter your bus no");
   			int z;
			int w = length(&k);
			scanf("%d",&z);
			if(z > w){
				printf("\n\tBus is not available");
				goto ddd;
			}
	
			SeatReservation(&k,z);
			int c;
			printf("\n\t\tDo you wan't to continue ? If yes then press 1 ");
			scanf("%d", &c);
			if(c == 1) {
				goto ddd;			
				fnPrintLine();
				break;
			}

			else{
				fnPrintLine();
				break;
			}	
			
		case 4: /*showing status of asked bus*/
			fnPrintLine();
			printf("\n\n................................................................................."); 
			printf("\n\n\t\tWelcome");
			eee: printf("\n\n\t\tEnter your bus no");
   			int q;
			int u = length(&k);
			scanf("%d",&q);
			if(q > u){
				printf("\n\tBus is not available");
				goto eee;
			}

			fnShowStatus(&k, q);
			int e;
			printf("\n\t\tDo u wan't to continue ? If yes then press 1 ");
			scanf("%d", &e);
			if(e == 1) {
				goto eee;
				fnPrintLine();
				break;
			}

			else{
				fnPrintLine();
				break;
			}	
			
		case 5: /*showing daily report */
			fnPrintLine();
			printf("\n\n................................................................................."); 
			ppp: printf("\n\n\t\tWelcome");
			fnDailyReport(&k);
			int d;
			printf("\n\t\tDo u wan't to continue ? If yes then press 1 ");
			scanf("%d", &d);
			if(d == 1) {
				goto ppp;
				fnPrintLine();
				break;
			}

			else{
				fnPrintLine();
				break;
			}
		
		case 6: /*Cancelling booked ticket*/
			fnPrintLine();
			printf("\n\n.................................................................................\n"); 
			lll: Cancelticket(&k);
			int l;
			printf("\n\t\tDo u wan't to continue ? If yes then press 1 ");
			scanf("%d", &l );
			if(l == 1) {
				goto lll;
				fnPrintLine();
				break;
			}

			else{
				fnPrintLine();
				break;
			}
		
		case 7: /*exit*/
			fnPrintLine();
			printf("\n\n................................................................................."); 
			printf("\n\n\t\tGood Bye");
			fnPrintLine();
			exit(0);

		default:
			printf("\n\n.................................................................................");  
			printf("\t\t\tYou have entered Wrong Choice!!!!");
			fnPrintLine();
			break;
				}
		
		}	
		return 0;
}
Пример #26
0
main() {

	portstr = getenv("FASTPORT");
	if(portstr!=NULL) {
	    if(strlen(portstr)<3) {
		fprintf(stderr, "FASTPORT environment variable must be");
		fprintf(stderr, " form: c;p. c and p are numerals for card");
		fprintf(stderr, " and port respectively\n");
		return -1;
	    } else {
		card = portstr[0] - '0';
		port = portstr[2] - '0';
	    }
	}
	if(card<0 || card>=NCARDS) {
	    fprintf(stderr, "card number out of range\n");
            return -1;
	}
	if(port<0 || port>2) {
	    fprintf(stderr, "port number out of range\n");
	    return -1;
	}
	if(!Init(card, port)) {
	    fprintf(stderr, "Unable to access device\n");
	    Finish();
	    exit(-1);
	}

	getflag = 0;
	oldxoffset = 0;
	oldyoffset = 0;
	strcpy(imagename,"image.cel");
	xmax = 40;
	ymax = 25;
	while(1) {
	    printmenu();
	    gets(tempstr);
	    c = tempstr[0];
	    printf("\n");
	    if(c == 'i') {
		system("down -S < /u1/gg/bin/face64.out");
		newcel();
	    }
	    if(c == 'd') {
		system("ls -C *.cel | more");
	    }
	    if(c == '!') {
	        printf("Unix command >");
	 	fflush(stdin) ;
		gets(tempstr);
		printf("\n");
		system(tempstr);
		printf("\nhit return to continue");
		fflush(stdin);
		gets(tempstr);
	    }
	    if(c == 'h') {
		if(fopen("/u1/gg/bin/face.doc","r") == NULL) {
		    printf("\nHelp file not in /u1/gg/bin\n");
		} else {
		    system("more /u1/gg/bin/face.doc");	        
		}
	    }
	    if(c == 'l') {
		getimagename();
		loadcel();
	    }
	    if(c == 's') {
		getimagename();
		savecel();
	    }
	    if(c == 'n') {
		newcel();
	    }



	    if(c == 'r') {
		getsequencename();
		read_sequence_file();
		getflag = 0;
	    }

	    if(c == 'w') {
		getsequencename();
		write_sequence_file();
		getflag = 0;
	    }

	    if(c == 'g') {
		get_a_sequence();
		getflag = 1;
	    }

	    if(c == 'p') {
		put_a_sequence();
	    }


	    if(c == 'P') {
		buf[0] = 1;
		down(buf,(word)1,(word)0x15);
		Cont();
		system("sleep 1");
		ffile = fopen(".ptemp","w");
		putc(40,ffile);
		putc(14,ffile);
		putc(0,ffile);			/* black edges */
		putc(0,ffile);
		putc(0,ffile);
		putc(0,ffile);
		up(buf,(word)4480,(word)0xa000);	/* get bitmap */
		for(i=0;i<4480;i++) putc(buf[i],ffile);
		for(i=0;i<560;i++) putc(0xde,ffile);	/* pink/blue */
		for(i=0;i<560;i++) putc(0x01,ffile);	/* gray bkgrnd */
		fclose(ffile);
		system("pixit < .ptemp | lpr &");
		buf[0] = 0;
		down(buf,(word)1,(word)0x15);
		Cont();	
	    }

	    if(c == 'q') {
		if (getflag) {
		    printf("sequences not written. Quit? (y/n)");
		    gets(tempstr);
		    c = tempstr[0];
		    printf("\n");
		    if (c == 'y') {
	 		exit(0);
		    }
		} else {
		    exit(0);
		}
	    }
	}
}
Пример #27
0
int main() {
    typedef struct dob {
        int dd;
        int mm;
        int yy;
    } date;

    typedef struct employee {
        char name[20];
        int basic;
        int pday;
        int id;
        date b, j;
    } emp;

    int choice, i, l, dd, mm, yy, id1, flag = 0;
    int p, b;
    long sal;
    emp e;
    char nxt, name[20], ch;
    FILE *fp, *fn, *ft;

    while(1) {
        fp = fopen("new.txt", "rb+");
        if(fp == NULL) {
            fp = fopen("new.txt","wb+");
            if(fp == NULL) {
                printf("Cannot create file");
                exit(1);
            }
        }
        else {
            fp = fopen("new.txt","ab+");
            if(fp == NULL) {
                printf("Cannot OPEN file");
                exit(1);
            }
        }
        choice = printmenu();
        switch(choice) {
        case 1:
            /***adding info of new employee***/
            do {
                printf("\nEnter emp name:");
                fflush(stdin);
                scanf("%s", e.name);
                l = strlen(e.name);
                e.name[l] =  '\0';
                printf("\nEnter date of birth of emp:");
                scanf("%d%d%d", &e.b.dd, &e.b.mm, &e.b.yy);
                printf("\nEnter emp basic salary:");
                scanf("%d", &e.basic);
                printf("\nEnter present days of emp:");
                scanf("%d", &e.pday);
                printf("\nEnter emp id:");
                scanf("%d", &e.id);
                printf("\nEnter date of joining:");
                scanf("%d%d%d", &e.j.dd, &e.j.mm, &e.j.yy);
                fwrite(&e, sizeof(e), 1, fp);
                printf("\nDo u want to add another record?: y/n\n");
                fflush(stdin);
                scanf("%s", &ch);
            } while(ch == 'y');
            fclose(fp);
            break;
        case 2:
            /***display***/

            fseek(fp, 0, SEEK_SET); //this moves file cursor to start of the file
            printf("-------------------------------------------------------------\n");
            printf("ID\tName\t DOB\tbasic salary\tPresent Days\tJoining Date\n");
            printf("-------------------------------------------------------------\n");
            while(fread(&e, sizeof(e), 1, fp) == 1) { // read the file and fetch the record one record per fetch
                printf("%d\t", e.id);
                printf("%s\t", e.name);
                printf("%d/%d/%d\t", e.b.dd, e.b.mm, e.b.yy);
                printf("%d\t\t", e.basic);
                printf("%d\t", e.pday);
                printf("%d/%d/%d\n", e.j.dd, e.j.mm, e.j.yy);
            }
            break;
        case 3:
            /***search the record***/
            printf("1. Search by name\n");
            printf("2. Search by id\n");
            printf("3.Search by joining date\n");
            scanf("%d", &i);
            switch(i) {
            case 1:/***Search by name***/
                printf("-------Search Employee By Name-------\n");
                printf("Enter employee Name:\n");
                scanf("%s",name);
                rewind(fp);
                while(fread(&e, sizeof(e), 1, fp)!=0) {
                    if(strcmp(e.name, name) == 0) {
                        printf("Record found:\n");
                        printf("ID:%d\tName:%s\tDOB:%d/%d/%d\tbasic salary:%d\tpresent days:%d\tJoin Date:%d/%d/%d\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
                        flag = 1;
                        break;
                    }
                }
                fclose(fp);
                if(flag == 0)
                    printf("Record not found\n");
                break;
            case 2:/***Search by id***/
                printf("-------Search Employee By Id-------\n");
                printf("Enter the emp id: ");
                scanf("%d", &id1);
                rewind(fp);
                while(fread(&e, sizeof(e), 1, fp) == 1) {
                    if(e.id == id1) {
                        printf("Record found:\n");
                        printf("ID:%d\tName:%s\tDOB:%d/%d/%d\tbasic  salary:%d\t\tpresent days:%d\tJoin Date:%d/%d/%d\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
                        flag = 1;
                        break;
                    }
                }
                fclose(fp);
                if(flag == 0)
                    printf("\nRecord not found");
                break;
            case 3:/***Search by joining date***/
                printf("-------Search Employee By Id-------\n");
                printf("Enter the date: ");
                scanf("%d%d%d", &dd, &mm, &yy);
                rewind(fp);
                while(fread(&e, sizeof(e), 1, fp) == 1) {
                    if(dd == e.j.dd && mm == e.j.mm && yy == e.j.yy) {
                        printf("Record found:\n");
                        printf("ID:%d\tName:%s\tDOB:%d/%d/%d\tbasic  salary:%d\tpresent days:%d\tJoin Date:%d/%d/%d\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
                        flag = 1;
                        break;
                    }
                }
                fclose(fp);
                if(flag == 0)
                    printf("\nRecord not found");
                break;
            }
            break;

        case 4:
            /***delete***/
            printf("Enter emp id to delete:");
            scanf("%d", &id1);
            ft = fopen("temp.txt", "ab+");
            fn = fopen("abc.txt", "wb+");
            while(fread(&e, sizeof(e), 1, fp) == 1) {
                if(e.id == id1) {
                    fwrite(&e, sizeof(e), 1 , ft);
                    flag = 1;
                }
                else
                    fwrite(&e, sizeof(e), 1 , fn);
            }
            fclose(fp);
            fclose(fn);
            remove("new.txt");
            rename("abc.txt", "new.txt");
            if(flag == 0)
                printf("Record not found\n");
            else
                printf("Record is deleted\n");
            break;

        case 5:
            /***Modify the record***/
            printf("Enter the employee name to modify:\n");
            scanf("%s", name);
            //rewind(fp);
            while(fread(&e, sizeof(e), 1, fp) == 1) { /// fetch all record from file
                if(strcmp(e.name, name) == 0) { ///if entered name matches with that in file
                    printf("Existing record:\n");
                    printf("ID:%d\tName:%s\tDOB:%d/%d/%d\tbasic  salary:%d\tpresent days:%d\tJoin Date:%d/%d/%d\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);

                    printf("Update basic  salary: y / n? :");
                    scanf("%s", &ch);
                    if(ch == 'y') {
                        printf("Enter new basic  salary:");
                        scanf("%d", &e.basic);
                    }
                    printf("Update present days: y / n? :");
                    scanf("%s", &ch);
                    if(ch == 'y') {
                        printf("Enter present days:");
                        scanf("%d", &e.pday);
                    }
                    printf("Update name: y / n? :");
                    scanf("%s", &ch);
                    if(ch == 'y') {
                        printf("Enter modified name:");
                        scanf("%s", e.name);
                    }
                    printf("Update DOB: y / n? :");
                    scanf("%s", &ch);
                    if(ch == 'y') {
                        printf("Enter modified date:");
                        scanf("%d%d%d", &e.b.dd, &e.b.mm, &e.b.yy);
                    }

                    //printf("%u\n", &fp);
                    fseek(fp, -(sizeof(e)),SEEK_CUR); /// move the cursor 1 step back from current position
                    //printf("%u", &fp);
                    fwrite(&e, sizeof(e), 1, fp); /// overwrite the record
                    flag = 1;
                    break;
                }
            }
            if(flag == 0)
                printf("Record not found\n");
            else {
                printf("Record is Updated\n");
                printf("ID:%d\tName:%s\tDOB:%d/%d/%d\tbasic salary:%d\tpresent days:%d\tJoin Date:%d/%d/%d\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
            }
            fclose(fp);
            break;

        case 6:
            /*calculate salary slip*/

            printf("Enter ID of d emp: ");
            scanf("%d", &id1);
            while(fread(&e, sizeof(e), 1, fp) == 1) {
                if(id1 == e.id) {
                    p = e.pday;
                    b = e.basic;
                    sal = p * b;
                    flag = 1;
                }
            }
            if(flag == 1) {
                printf("Salary Details:\n");
                printf("ID:%d\tName:%s\tBasic:%d\tPresent Days:%d\tNet Salary:%lu\n", e.id, e.name, e.basic, e.pday, sal);
            }
            fclose(fp);
            break;

        case 7:
            /*Exit*/
            exit(0);
            break;
        }
    }
    return 0;
}
Пример #28
0
int main(){
	typedef struct dob {
		int dd;
		int mm;
		int yy;
	} date;

	typedef struct employee {
		char name[20];
		int basic;
		int pday;
		int id;
		char dep[20];
		date b, j;
	}emp;
	enum cases {A, B};
	int choice, i, l1, l2, p, b, dd, mm, yy, id1, flag = 0;
	long sal;
	emp e;
	char nxt, name[20], ch, dep[20], c,d;
	FILE *fp, *fn, *ft,*fx; 
	
	while(1) {
	fp = fopen("file.txt", "rb+");
	if(fp == NULL){
		fp = fopen("file.txt","wb+");
		if(fp == NULL){
			printf("Cannot create file");
			exit(1);
		}
	}
	else{
		fp = fopen("file.txt","ab+");
		if(fp == NULL){
			printf("Cannot OPEN file");
			exit(1);
		}
	}
	choice = printmenu();
	switch(choice) {
		case 1:
		/***adding info of new employee***/
			system("clear");
			do {
				printf("\nEnter emp name:");
				fflush(stdin);
				scanf("%s", e.name);
				l1 = strlen(e.name);
				e.name[l1] =  '\0';
				printf("\nEnter date of birth of emp:");
				scanf("%d%d%d", &e.b.dd, &e.b.mm, &e.b.yy);
				printf("\nEnter emp basic salary:");
				scanf("%d", &e.basic);
				printf("\nEnter present days of emp:");
				scanf("%d", &e.pday);
				printf("\nEnter emp id:");
				scanf("%d", &e.id);
				printf("\nEnter date of joining:");
				scanf("%d%d%d", &e.j.dd, &e.j.mm, &e.j.yy);
				printf("Enter department:");
				scanf("%s", e.dep);
				l2 = strlen(e.dep);
				e.dep[l2] =  '\0';
				fwrite(&e, sizeof(e), 1, fp);
				printf("\nDo u want to add another record?: y/n\n");
				fflush(stdin);
				scanf("%s", &ch);
	 		} while(ch == 'y');
			fclose(fp);
			break;
		case 2:
			/***display***/
			system("clear");
			printf("\n\n");
			printf("\t\tDisplay options:\n");
			printf("\t\t\t[A]View All\n");
			printf("\t\t\t[B]View Department wise\n");
			printf("\n\t\tEnter your choice:");
			scanf("%s", &ch);
			switch(ch) {
				case 'A': /**Display all records**/
					system("clear");
					fseek(fp, 0, SEEK_SET); //this moves file cursor to start of the file
					printf("--------------------------------------------------------------------\n");
					printf("ID\tName\t DOB\tbasic salary\tPresent Days\tDepartment\tJoin Date\n");
					printf("--------------------------------------------------------------------\n");
					// read the file and fetch the record one record per fetch
					while(fread(&e, sizeof(e), 1, fp) == 1) { 	
				   		printf("%d\t", e.id);
						printf("%s\t", e.name);
						printf("%d/%d/%d\t", e.b.dd, e.b.mm, e.b.yy);
						printf("%d\t\t", e.basic);
						printf("%d\t", e.pday);
						printf("%s\t", e.dep);
						printf("%d/%d/%d\n", e.j.dd, e.j.mm, e.j.yy);	
					}
					scanf("%c", &c);
					if(c == 'e')
						break;
					break;

				case 'B':/**Display Departmentwise**/
					system("clear");
					printf("\tEnter department:");
					scanf("%s", dep);
					printf("============ %s DEPARTMENT===========\n", dep);
					fseek(fp, 0, SEEK_SET); /*this moves file cursor to start of the file*/
					printf("---------------------------------------------------------------------\n");
					printf("ID\tName\t DOB\tbasic salary\tPresent Days\tJoining Date\n");
					printf("---------------------------------------------------------------------\n");

					/*read the file and fetch the record one record per fetch*/
					while(fread(&e, sizeof(e), 1, fp) == 1) { 
						if(strcmp(e.dep, dep) == 0) {	
					   		printf("%d\t", e.id);
							printf("%s\t", e.name);
							printf("%d/%d/%d\t", e.b.dd, e.b.mm, e.b.yy);
							printf("%d\t\t", e.basic);
							printf("%d\t", e.pday);
							printf("%d/%d/%d\n", e.j.dd, e.j.mm, e.j.yy);	
						}
					}
					scanf("%c", &c);
					if(c == 'e')
						break;
					break;
			}
			printf("\nGo to main menu-Press y : ");
			scanf("%c", &c);
				break;
			break;
		case 3:
			/***search the record***/
			system("clear");
			printf("\t\tSearch Options\n");
			printf("\t\t\t1. Search by name\n");
			printf("\t\t\t2. Search by id\n");
			printf("\t\t\t3. Search by Department\n");
			printf("\t\t\t4.Search by joining date\n");
			printf("\n\t\tEnter your choice:");
			scanf("%d", &i);
			switch(i) {
				case 1:/***Search by name***/
					system("clear");
					printf("-------Search Employee By Name-------\n");
					printf("Enter employee Name:\n");
     					scanf("%s",name);
					rewind(fp);
					while(fread(&e, sizeof(e), 1, fp)!=0) {
						if(strcmp(e.name, name) == 0) {
							printf("Record found:\n\n");
							printf("ID:%d\nName:%s\nDOB:%d/%d/%d\nBasic salary:%d\nPresent days:%d\nJoin Date:%d/%d/%d\n\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
							flag = 1;
							break;
						}
					}
					fclose(fp);
					if(flag == 0) 
						printf("Record not found\n");
					scanf("%c", &c);
						break;		
					break;
				case 2:/***Search by id***/
					system("clear");
					printf("---------Search Employee By Id---------\n");
					printf("Enter the emp id: ");
					scanf("%d", &id1);
					rewind(fp);
					while(fread(&e, sizeof(e), 1, fp) == 1) {
						if(e.id == id1) {
							printf("Record found:\n\n");
							printf("ID:%d\nName:%s\nDOB:%d/%d/%d\nBasic salary:%d\nPresent days:%d\nJoin Date:%d/%d/%d\n\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
							flag = 1;
							break;
						}
					}
					fclose(fp);
					if(flag == 0)
						printf("\nRecord not found");
					scanf("%c", &c);	
						break;			
					break;
				case 3:/****Search by Department****/
					system("clear");
					printf("-------Search Employee By Department-------\n");
					printf("Enter Department:\n");
     					scanf("%s",dep);
					rewind(fp);
					while(fread(&e, sizeof(e), 1, fp)!=0) {
						if(strcmp(e.dep, dep) == 0) {
							printf("Record found:\n\n");
							printf("ID:%d\nName:%s\tDOB:%d/%d/%d\nBasic salary:%d\nPresent days:%d\nJoin Date:%d/%d/%d\n\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
							flag = 1;
							break;
						}
					}
					fclose(fp);
					if(flag == 0) 
						printf("Record not found\n");
					scanf("%c", &c);
						break;	
					break;
				case 4:/***Search by joining date***/
					system("clear");
					printf("---------Search Employee By Id----------\n");
					printf("Enter the date: ");
					scanf("%d%d%d", &dd, &mm, &yy);
					rewind(fp);
					while(fread(&e, sizeof(e), 1, fp) == 1) {
						if(dd == e.j.dd && mm == e.j.mm && yy == e.j.yy) {
							printf("Record found:\n\n");
							printf("ID:%d\nName:%s\nDOB:%d/%d/%d\nBasic  salary:%d\tPresent days:%d\nJoin Date:%d/%d/%d\n\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
							flag = 1;
							break;
						}
					}
					fclose(fp);
					if(flag == 0)
						printf("\nRecord not found");
					scanf("%c", &c);
						break;		
					break;
				 
			}
			printf("Go to main menu-Press y : \n");
			scanf("%c", &c);	
				break;	
			break;

		case 4:
			/***delete***/
			system("clear");
			printf("Enter emp id to delete:");
			scanf("%d", &id1);
			ft = fopen("temp.txt", "ab+");
			fn = fopen("abc.txt", "wb+");
			while(fread(&e, sizeof(e), 1, fp) == 1) {
				if(e.id == id1) {
					fwrite(&e, sizeof(e), 1 , ft);
					flag = 1;
				}
				else
				fwrite(&e, sizeof(e), 1 , fn);
			}
			fclose(fp);
			fclose(fn);
			remove("file.txt");
			rename("abc.txt", "file.txt");
			if(flag == 0)
				printf("Record not found\n");
			else 
				printf("Record is deleted\n");

			printf("Go to main menu-Press y : ");
			scanf("%c", &c);	
			//if(c == 'e'){
///printf("ddddf");
///				break;}	
			break;

		case 5:
			/***Modify the record***/
			system("clear");
			printf("Enter the employee name to modify:\n");
			scanf("%s", name);
			
			fx = fopen("file.txt", "rb+");
			while(fread(&e, sizeof(e), 1, fx) == 1) { /* fetch all record from file*/
                        	if(strcmp(e.name, name) == 0) { /*if entered name matches with that in file*/
					printf("Existing record:\n");
                            		printf("ID:%d\tName:%s\tDOB:%d/%d/%d\tbasic  salary:%d\tpresent days:%d\tJoin Date:%d/%d/%d\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);

					printf("Update basic  salary: y / n? :");
					scanf("%s", &ch);
					if(ch == 'y') {
						printf("Enter new basic  salary:");
						scanf("%d", &e.basic);
					}
					printf("Update present days: y / n? :");
					scanf("%s", &ch);
					if(ch == 'y') {
						printf("Enter present days:");
						scanf("%d", &e.pday);
					}
					printf("Update name: y / n? :");
					scanf("%s", &ch);
					if(ch == 'y') {
						printf("Enter modified name:");
						scanf("%s", e.name);
					}
					printf("Update DOB: y / n? :");
					scanf("%s", &ch);
					if(ch == 'y') {
						printf("Enter modified date:");
						scanf("%d%d%d", &e.b.dd, &e.b.mm, &e.b.yy);
					}
					/* move the cursor 1 step back from current position*/
                            		fseek(fx, -(sizeof(e)),SEEK_CUR); 
					/*overwrite the record*/
                            		fwrite(&e, (sizeof(e)), 1, fx); 
					flag = 1;
					break;
                        	}
			}
			if(flag == 0)
				printf("Record not found\n");
			else{
				printf("Record is Updated\n");
				printf("ID:%d\tName:%s\tDOB:%d/%d/%d\tbasic salary:%d\tpresent days:%d\tJoin Date:%d/%d/%d\n", e.id, e.name, e.b.dd, e.b.mm, e.b.yy, e.basic, e.pday, e.j.dd, e.j.mm, e.j.yy);
			}
			fclose(fx);
			fclose(fp);
			printf("\nGo to main menu-press y");
			scanf("%c", &d);
				break;
			break;

		case 6:
			/*calculate salary slip*/
			system("clear");
			printf("Enter ID of d emp: ");
			scanf("%d", &id1);
			while(fread(&e, sizeof(e), 1, fp) == 1) {
				if(id1 == e.id) {
					p = e.pday;
					b = e.basic;
					sal = p * b;
					flag = 1;
					break;
				}
			}
			if(flag == 1) {
				printf("\n");
				printf("Department:%s\n", e.dep);
				printf("Salary Details:\n");
				printf("ID:%d\nName:%s\nBasic:%d\nPresent Days:%d\nNet Salary:%lu\n\n", e.id, e.name, e.basic, e.pday, sal);
			}
			fclose(fp);
			printf("Go to main menu-Press y:\n");
			scanf("%c", &c);	
				break;	
			break;
			
		case 7:
			/*Exit*/
			exit(0);
			break;

		default:
			printf("Invalid Choice\n");
	}
	scanf("%c", &c);	
	if(c == 'e' || c == 'E')
		break;	
	}
	return 0;
}
Пример #29
0
int main()
{
	int choice,  res,  no1, no2, ch;
	double n, m, s1, s2, res1, ans, val, num;
	float x, y;
	double result = 0, n1 = 0, fradecimal;
	long y1;
	char c;
	char frabinary[100], hexa[MAX];
	long int binaryval;
	div_t1 temp;
	poly * poly1, * poly2, * poly3;
	FILE *fp;
	printf("\n\n....NEW USER FIRST READ THE MANUAL TEXT FILE TO UNDERSTANS THE FUNCTIONS USAGE....\n\n");
	while(1) {
		printmenu1();
		printf("Enter your choice\n");
		scanf("%d", &ch);
		switch(ch) {
			case 1:
			
				fp = fopen("Manual.txt", "r");
				if(!fp)
					printf("Cannot open file\n");
				while((c = fgetc(fp) )!= EOF)
					printf("%c", c);
					fclose(fp);
				break;
			case 2:
				while(1) {
					printmenu();
					printf("Enter your choice\n");
					scanf("%d" ,&choice);
					switch(choice) {
						case 1:
							printf(".....sqrt() function finds the square root of a number.....\n");	
							printf("Enter your number:\n");
							scanf("%lf", &n);
							m = sqrt(n); //square root
							if( m == 0) {
								printf(" You entered negative number\n");
								break;				
							}
							printf("square root is %.3lf\n", m);
							waita();
							break;
						case 2:
							printf(".....mod() finds remainder when one number is divided 									by 2nd 	number.....\n"); 
						
							printf("enter the number to be divided :\t\n");
							scanf("%lf",&s1);
							printf("enter the divisor:\t\n");
							scanf("%lf",&s2);
							ans = fmod(s1, s2); //remainder
							printf("remainder is : %lf\n", ans);
							waita();
							break;
						case 3:
							printf(".....fabs()  finds the absolute value of floating 									point number.....\n");
						
							printf("Enter the number to find the absolute value\n");
							scanf("%lf", &val);
							res1 = fabs(val);  //absolute value
							printf("The absolute value of %lf is %lf\n", val, res1);
							waita();
							break;
						case 4:
							printf(".....ceilx() function finds ceil value of a 									number.....\n");	
							printf("Enter the value\n");
							scanf("%lf", &val);
							ans = ceilx(val); //ceil function
							printf("Value=%lf\n", ans);
							waita();
							break;   
 	
						case 5:
							printf(".....floorx() function finds floor value of a 										number.....\n");	
							printf("Enter the value\n");
							scanf("%lf", &val);
   							ans = floorx(val); //floor function
							printf("Value=%lf\n", ans);
							waita();
							break;
						case 6:
							printf(".....expoential() function finds expoential value of a 									number 	i.e. e^x.....\n");
							printf("Enter the value of x\n");
    							scanf("%lf", &n);
   						        printf("e^x = %lf\n", exponential(n)); //exponential function
							waita();
							break;
						case 7:
							printf(".....hypot()finds the value of hypotenuse when two 									sides are given.....\n");
							
							printf("Enter sides: \n");
							scanf ("%lf %lf",&s1,&s2);
							printf("Hypotenus of %f %f is: %f\n", s1, s2,hypot(s1,s2)); 								//hypotenuse function
							waita();
							break;
						case 8: 
							printf(".....cbrt() finds the cube root of proper number i.e. 									cbrt(8)= 2.....\n"); 
						 
							printf("enter the number to find the cube root\n");
 							scanf("%lf",&n1);
 							if(n1 < 0) {
 	
 								 printf("enter only +ve integer value\n");
						  		 waita();
 								 break;
 							}
 							result = cbrtx(n1); //cube root function
 							if(result)
 								 printf("cube root of %lf is %lf\n",n1,result);
 								else {
								printf("not a proper value for finding the cube 										root\n");
								waita();
 								break;
							}	
							
							waita();
							break;
						case 9:
							printf(".....pow() function finds the x^y power.....\n");
							printf("Enter the number and the power\n");
							scanf("%lf%lf", &s1, &s2);
							res1 = Pow(s1, s2); //power function
							printf("The %lf^%lf is %lf\n", s1, s2, res1);
							
							waita();
							break;
						case 10:
							printf(".....trunc() function truncates the floating 									points.....\n");	
							printf("Enter the value for truncating\n");
							scanf("%lf", &s1);
							res1 = trunc(s1); // truncating a number
							printf("The value after truncating is %lf\n", res1);
							
							waita();
							break;
						case 11:
							printf(".....round() function rounds up a floating point 									number..... \n");
							printf("Enter the value for rounding\n");
							scanf("%lf", &s1);
							res1 = round(s1); //rounding a number
							printf("The value after rounding is %lf\n", res1);
							
							waita();
							break;
						case 12:
							printf(".....abs() function finds absolute value of integer 									number.....\n");
							printf("Enter the integer number to find the absolute value\n");
							scanf("%lf", &n);
							if(n - (int)n == 0) {
								res = abs(n);  //absolute value
								printf("The absolute value of %lf is %d\n", n, res);
								waita();
								break;
							}
							else {
								printf("Enter integer number\n");
								waita();
								break;
							}
							waita();
							break;
						case 13:
							printf(".....fmax() function finds maximum between two 									numbers.....\n");	
							printf("Enter two numbers to find maximun number\n");	
							scanf("%lf%lf", &s1, &s2);
							res1 = fmax(s1,s2);
							printf("The max number is %f\n",res1);
							waita();
							break;
						case 14:
							printf(".....fmin() function finds minimum between two 									numbers.....\n");	
							printf("Enter two numbers to find minimum number\n");	
							scanf("%lf%lf", &s1, &s2);
							res1 = fmin(s1,s2);
							printf("The min number is %f\n",res1);
							waita();
							break;
						case 15:
							printf(".....fdim()finds +ve difference bet^n 2 no's & if fails 									it returns 0.....\n"); 
						
							printf("Enter two numbers to find difference of two numbers\n");
							scanf("%lf%lf", &s1, &s2);
							res1 = fdim(s1,s2);
							if(res1 == 0) {
								printf("This functions returns 0 when  first number is 										less than or equal to second number\n");
								waita();
								break;
							}		
							printf("The positive Difference  is %f\n",res1);
							waita();
							break;
						case 16:
							printf(".....roundf() function rounds up a floating 										value.....		\n");	
							printf("Enter the value for rounding\n");
							scanf("%f", &x);
							y = roundf(x);
							printf("The value after rounding is %f\n", y);
							waita();
							break;
						case 17:
							printf(".....lround() function rounds up a long value.....\n");
							printf("Enter the value for rounding\n");
							scanf("%lf", &n);
							y1 = lround(n);
							printf("The value after rounding is %li\n", y1);
							waita();
							break;
						case 18:
							printf(".....add_poly() function adds two polynomials.....\n");
							printf("\nCreate 1st expression\n");
							create(&poly1);
							printf("\nStored the 1st expression");
							show(poly1);
		
							printf("\nCreate 2nd expression\n");
							create(&poly2);
							printf("\nStored the 2nd expression");
							show(poly2);
						
							add_poly(&poly3, poly1, poly2);
							show(poly3);
							waita();
							break;
						case 19:
							printf(".....sub_poly() function subtract two 											polynomials.....		\n");	
							printf("\nCreate 1st expression\n");
							create(&poly1);
							printf("\nStored the 1st expression");
							show(poly1);	
							printf("\nCreate 2nd expression\n");
							create(&poly2);
							printf("\nStored the 2nd expression");
							show(poly2);
	
							sub_poly(&poly3, poly1, poly2);
							show(poly3);
							waita();
							break;
						case 20:
							printf(".....division() function givesquotient and remainder 									after division.....\n");
							printf("Enter divident\n");
							scanf("%d", &no1);
							printf("Enter divisor\n");
							scanf("%d", &no2);
							temp = division(no1, no2);
							printf("quotient=%d\tremainder=%d\n", temp.quot, temp.rem);
							waita();
							break;			
						case 21:
							printf(".....ldexp() function returns value * 									2^expoential.....		\n");
							printf("Enter the value\n");
							scanf("%lf", &n);
							printf("Enter the integer exponent\n");
							scanf("%d", &no1);
							m = ldexp(n, no1);
							printf("value=%lf\n", m);	
							waita();
							break;;
						case 22:
							printf(".....exp2() function returns 2^expoential.....\n");
							printf("Enter the expoential\n");
							scanf("%lf", &n);
							m = exp2(n);
							printf("exp2(%lf)=%lf\n", n, m);
							waita();
							break;
						case 23:
							printf(".....tgamma() fuction calculates gamma value.....\n");
							printf("Enter the number to find gamma value\n");
							scanf("%lf", &num);
							if( num <= 0) {
								printf("Gamma of negative number and 0 is not 										defined		\n");	
								waita();
								break;
							}
							ans = tgamma(num);
							printf("gamma(%lf)=%lf\n", num, ans);
							waita();
							break;			
						case 24:
							printf(".....fact() function returns factorial of a 										number.....		\n");	
							printf("Enter number to find factorial\n");
							scanf("%lf", &n);
							ans = fact(n);
							printf("The factorial of %lf is %lf\n", n, ans);
							waita();
							break;
						case 25:
							printf(".....square() function calculates square of a 									number.....\n");	
							printf("Enter number to find square of entered number\n");
							scanf("%lf", &n);
							ans = square(n);
							printf("The square of %lf is %lf\n",n, ans);
							waita();
							break;
						case 26:
							printf(".....cube() function calculates cube of a 									number.....		\n");	
							printf("Enter number to find cube of a entered number\n");
							scanf("%lf", &n);
							ans = cube(n);
							printf("The cube of %lf is %lf\n",n, ans);
							
							waita();
							break;
						case 27:
							printf("dec_bin() function converts decimal number into 								binary			\n");
							printf("Enter any fractional Decimal number\n");
							scanf("%lf", &fradecimal);
							printf("eduivalent binary value is %lf\n",dec_bin(fradecimal));
							waita();
							break;
						case 28:
							printf("bin_dec() function converts binary number into 								decimal 		\n");
							printf("Enter any fractional Binary number\n");
							scanf("%s", frabinary);
							printf("eduivalent decimal value is %lf\n",bin_dec(frabinary));
							waita();
							break;
						case 29:
							printf("This fun. converts decimal number to octal number\n");
							printf("Enter a decimal number:\n ");
       							scanf("%d", &no1);
       							printf("%d in decimal = %d in octal\n", no1, 									decimal_octal(no1));	
							waita();
							break;
						case 30:
							printf("This fun. converts octal number to decimal number\n");
							printf("Enter a octal number:\n ");
       							scanf("%d", &no1);
       							printf("%d in octal = %d in decimal\n", no1, 									decimal_octal(no1));	
							waita();
							break;
						case 31:
							printf("This fun. converts binary number to octal number\n");
							printf("Enter a binary number:\n ");
       							scanf("%d",&no1);
        						printf("%d in binary = %d in octal\n", no1, binary_octal(no1));
							waita();
							break;
						case 32:
							printf("This fun. converts octal number to binary number\n");
							printf("Enter a octal number:\n ");
        						scanf("%d",&no1);
        						printf("%d in octal = %d in binary\n",no1, octal_binary(no1));
							waita();
   
							break;
						case 33:
							printf("This function converts binary into hex number\n");
							printf("Enter the binary number:\n ");
    							scanf("%ld", &binaryval);
    
    							printf("Equivalent hexadecimal value: %lX\n", 									binary_hex(binaryval));
							waita();
							break;
						case 34:
							printf("This function converts hex into binary number\n");
							printf("Enter the value for hexadecimal\n ");
    							scanf("%s", hexa);
   							hex_binary(hexa);
							waita();
							break;
						case 35:
							return 0;
						default:
							printf(".....wrong choice.....\n");
					}	
				}	
			case 3:	
				return 0;
			default:
				printf("Invalid Choice\n");
			}	
			
		} 
		return 0;		
	}		
Пример #30
0
int main(int argc, char *argv[])
{
	// initial variables used throughout all of the commands
	int i;
	int SERVERPORT;
	char SERVERHOST[MAX_HOST_LEN], SERVERUSERNAME[MAX_USERNAME_LEN], SERVERPASSWORD[MAX_ENC_PASSWORD_LEN], SERVERPORTstr[MAX_PORT_LEN];
	char TABLE[MAX_TABLE_LEN], KEY[MAX_KEY_LEN];
	char **key = malloc(sizeof(char**)*800);
	char PREDICATES_1[500];
	char PREDICATES[500];
	void *conn = NULL;
	int status;
	struct storage_record r;
	int authenticated = 0;

	do{
		printmenu(&i); // function to prompt the user for the menu and read in and update the variable i

		if(i == 0){// Connect to server
			if(conn != NULL)
				printf("You are already connected. Please choose another option.\n\n");
			else
			{
				conn = storage_connect("localhost",2222);
				if(!conn)
				{
					printf("Cannot connect to server @ %s:%d. Error code: %d.\n", SERVERHOST, SERVERPORT, errno);
					//return -1;
				}
				else printf("\nUser conncected with the server\n");
				status = storage_auth("admin", "dog4sale", conn);
				if(status != 0)
				{
					printf("storage_auth failed with username '%s' and password '%s'. " \
					"Error code: %d, status: %d\n", SERVERUSERNAME, SERVERPASSWORD, errno, status);
					//storage_disconnect(conn);
					//return status;
				}
				else{
					authenticated = 1;
					printf("\nUser authenticated with the server\n");
				}
			}
		}
		if(i == 1)
		{// Connect to server
			if(conn != NULL)
				printf("You are already connected. Please choose another option.\n\n");
			else
			{
				printf("Enter the Server Host\n");
				fgets(SERVERHOST, MAX_HOST_LEN, stdin);
				sscanf(SERVERHOST, "%s", SERVERHOST);
				printf("Enter the Server Port\n");
				fgets(SERVERPORTstr, MAX_PORT_LEN, stdin);
				sscanf(SERVERPORTstr, "%d", &SERVERPORT);
				conn = storage_connect(SERVERHOST, SERVERPORT);
				if(!conn)
				{
					printf("Cannot connect to server @ %s:%d. Error code: %d.\n", SERVERHOST, SERVERPORT, errno);
					//return -1;
				}
				else printf("\nUser connected with the server\n");
			}
		}

		else if(i == 2)
		{// Authenticate the client.
			if(conn == NULL)
				printf("You are not connected yet. Please connect to the server first.\n\n");
			//else if(authenticated == 1)
				//printf("You are already authenticated. Please choose another option.\n\n");
			else
			{
				printf("Enter the UserName Host\n");
				fgets(SERVERUSERNAME, MAX_USERNAME_LEN, stdin);
				sscanf(SERVERUSERNAME, "%s", SERVERUSERNAME);
				printf("Enter the Password Host\n");
				fgets(SERVERPASSWORD, MAX_ENC_PASSWORD_LEN, stdin);
				sscanf(SERVERPASSWORD, "%s", SERVERPASSWORD);
				status = storage_auth(SERVERUSERNAME, SERVERPASSWORD, conn);
				if(status != 0)
				{
					printf("storage_auth failed with username '%s' and password '%s'. " \
							"Error code: %d, status: %d\n", SERVERUSERNAME, SERVERPASSWORD, errno, status);
				}
				else{
					authenticated = 1;
					printf("\nUser authenticated with the server\n");
				}
			}
		}

		else if(i == 3)
		{// SET command
			if(conn == NULL)
				printf("You are not connected yet. Please connect to the server first.\n\n");
			else
			{
				printf("Please enter the Table\n");
				fgets(TABLE, MAX_TABLE_LEN, stdin);
				sscanf(TABLE, "%s", TABLE);
				printf("Please enter the Key\n");
				fgets(KEY, MAX_KEY_LEN, stdin);
				sscanf(KEY, "%s", KEY);
				printf("Please Enter the record that you wish to store\n");
				fgets(r.value, MAX_VALUE_LEN, stdin);
				r.value[strlen(r.value)-1] = '\0';
				//strncpy(r.value, value, sizeof value);

				//This is for measuring the server processing time
				//remember when the process started
				clock_t t;
				t=clock();
				//issue set call to DATABASE with TABLE, KEY and r.value
				if(!strcmp(r.value,"null")){
					status = storage_set(TABLE,KEY,NULL,conn);
				}
				if(strcmp(r.value,"null"))
				status = storage_set(TABLE, KEY, &r, conn);
				//find how long it took to perform the GET operation
				//current time minus the time when the operation started
				t=clock()-t;

				if(status != 0)
				{
					printf("storage_set failed. Error code: %d.\n", errno);
				}
				else
					printf("storage_set: successful.\n");
			}
		}

		else if(i == 4)
		{// GET command
			if(conn == NULL)
				printf("You are not connected yet. Please connect to the server first.\n\n");
			//else if(authenticated == 0)
				//printf("You are not authenticated yet. Please authenticate first.\n\n");
			else
			{
				printf("Please enter the Table\n");
				fgets(TABLE, MAX_TABLE_LEN, stdin);
				sscanf(TABLE, "%s", TABLE);
				printf("Please enter the Key\n");
				fgets(KEY, MAX_KEY_LEN, stdin);
				sscanf(KEY, "%s", KEY);
				status = storage_get(TABLE, KEY, &r, conn);
				if(status != 0)
				{
					printf("storage_get failed. Error code: %d.\n", errno);
					storage_disconnect(conn);
					return status;
				}
				else
					printf("storage_get: the value returned for key '%s' is '%s'.\n", KEY, r.value);
			}
		}

		else if(i == 5)
		{// QUERY command
			if(conn == NULL)
				printf("You are not connected yet. Please connect to the server first.\n\n");
			else
			{
				printf("Please enter the Table\n");
				fgets(TABLE, MAX_TABLE_LEN, stdin);
				sscanf(TABLE, "%s", TABLE);

				printf("Please enter the Predicates\n");
				fgets(PREDICATES_1, 500, stdin);
				sscanf(PREDICATES_1, "%[^'\n]",PREDICATES);
				// (const char *table, const char *predicates, char **keys, const int max_keys, void *conn)
				status = storage_query(TABLE, PREDICATES, key, &r, conn);
				//int foundkeys = storage_query(INTTABLE, "col<-1", test_keys, MAX_RECORDS_PER_TABLE, test_conn);
				printf("status/number of keys: %d\n",status);
				if(status == -1)
				{
					printf("storage_query failed. Error code: %d.\n", errno);
					storage_disconnect(conn);
					return status;
				}
				else {
					int p = 0;

					int i = 0;

					while (key[i] != NULL){
						printf("key: '%s'\n", key[i]);
						i++;

					}
				}
			}
		}


		else if(i==6)
		{// Disconnect from server
			status = storage_disconnect(conn);
			if(status != 0)
			{
				printf("storage_disconnect failed. Error code: %d.\n", errno);
				return status;
			}
			else
			{
				conn = NULL;
				authenticated = 0;
				printf("You are now disconnected\n");
			}
		}
		else if (i==8){
			// import the census into the data base
			if(conn == NULL)
				printf("You are not connected yet. Please connect to the server first.\n\n");
			 FILE* fp;
			fp=fopen("census", "r");               //open the file for reading only
   			if(fp == NULL)
   			 printf("Error opening file");
  			 else
   			{
				int loop;
       				//populate the table with all the data in the data file (city + its population)
				do {
					char name[100];
					char value[MAX_VALUE_LEN];
					char line[100];
       					char *l = fgets(line, sizeof line, fp);
					if (!feof(fp)){
						sscanf(l, "%s %s", name, value);
						printf("name: %s , value: %s \n", name, value);
						strcpy(r.value,value);
						status = storage_set("census", name, &r, conn);
						if(status != 0)
						{
							printf("storage_set failed. Error code: %d.\n", errno);
						}			
					}
					
				   }
       				 while(!feof(fp));     //read the first line (city)	
   			}
		}

	} while (i!=7); // if i is 6, we want to exit from client

	// Exit
	return 0;
}