void pesquisar(struct tlist *l) { int num, j; cabecalho("PESQUISA"); if(filter_pass) { printf("\t\tDIGITE O NUMERO: "); geti(&num); j = search(num, l); if(j != -1) printf("\n\n\t\tITEM: %d - POSICAO %d. [ENTER]", l->item[j], j); else printf("\n\t\t# ERRO: NUMERO NAO ENCONTRADO! [ENTER]"); } else printf("\n\n\t\t# INSERIR DADOS! [ENTER]"); getche(); }
void main() { int i,j; for (i=1;i<=10;i++) { for (j=1;j<=i;j++) {printf("*");} printf("\n"); } for (i=9;i>=1;i--) { for (j=1;j<=i;j++) {printf("*");} printf("\n"); } getche(); }
static char *dos_kbd_gets(char *buf, int len) { int ch, count=0; do { buf[count++] = ch = getche(); } while (ch != '\r' && count < len-1); buf[count--] = '\0'; /* terminate string */ if (buf[count] == '\r') /* Enter key makes CR, so change to newline */ buf[count] = '\n'; fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */ fflush(stderr); return buf; }
//EXEMPLO REGISTRO COM TAMANHO FIXO CAMPO FIXO int main(void) { struct estrutura { char nome[30], sobrenome[30], end[30]; }ts; FILE *out; if ((out = fopen("arq.bin","w+b")) == NULL) { printf("Nao foi possivel abrir o arquivo"); getche(); return 0; } printf("nome: "); gets(ts.nome); while (strlen(ts.nome) > 0) { printf("sobrenome: "); gets(ts.sobrenome); printf("endereco: "); gets(ts.end); fwrite(&ts,sizeof(ts),1,out); printf("nome: "); gets(ts.nome); } rewind(out); while (fread(&ts,sizeof(ts),1,out)) { printf("\nnome: %s",ts.nome); printf("\nsobrenome: %s",ts.sobrenome); printf("\nendereco: %s",ts.end); getch(); } fclose(out); getch(); }
int main(int argc, char *argv[]) { char nombre[15], aux[50], seguir; float tarifa_hora, salario_semana; int horas_trab, cont=0; do{ system("cls"); printf("\n Ingrese nombre: \n"); fflush(stdin); gets(nombre); ////VALIDAR QUE EL NOMBRE NO SEA MAS LARGO QUE EL VECTOR///// while(strlen(aux)>24) { printf("\n ERROR....nombre largo...REINGRESE: \n"); fflush(stdin); gets(aux); } strcpy(nombre, aux); printf("\n Ingrese cantidad de horas trabajadas a la semana: \n"); scanf("%d", &horas_trab); printf("\n Ingrese tarifa por hora: \n"); scanf("%f", &tarifa_hora); salario_semana= (float)horas_trab* tarifa_hora; cont++; printf("\n El salario semanal es de:%.2f \n",salario_semana); printf("\n DESEA SEGUIR INGRSANDO DATOS? S/N \n"); seguir= tolower(getche()); }while(seguir=='s'); printf("\n La cantidad de usuarios que se les calculo el salario es:%d \n",cont); system("PAUSE"); return 0; }
/************************************************* Function: void SetupModule(SetUp *setinfo) Description: 设置模块 Calls: // 被本函数调用的函数清单 Called By: // 调用本函数的函数清单 Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序) Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序) Input: // 输入参数说明,包括每个参数的作 // 用、取值说明及参数间关系。 Output: // 对输出参数的说明。 Return: // 函数返回值的说明 Others: *************************************************/ void SetupModule(SetUp *setinfo) { INTERFACE_COLOR_3; setinfo=LoadSetup(); Displaysetup(setinfo); printf("\n\nDo you want to set up?:[ ]\b\b"); if (YesOrNo()==YES) { printf("\ntime(1~5):"); setinfo->speaktime=Select(1,5); printf("\ndelay(s):"); setinfo->speakdelay=Select(1,10)*1000; printf("\nautospeak(y/n):[ ]\b\b"); setinfo->autospeak=YesOrNo(); printf("\nautoback(y/n):[ ]\b\b"); setinfo->autoback=YesOrNo(); printf("\nautoinsearch(y/n):[ ]\b\b"); setinfo->autoinsearch=YesOrNo(); //lack () system("cls"); Displaysetup(setinfo); printf("\nDo you want to save it?:[ ]\b\b"); if (YesOrNo()==YES) { SaveSetup(setinfo); return; } else { return; } } else { printf("\nPress any key to back..."); getche(); return; } }
main() { PtrLista PtrInicio=NULL; char Dato; Dato='c'; Insertar(&PtrInicio,Dato); Dato='w'; Insertar(&PtrInicio,Dato); Dato='b'; Insertar(&PtrInicio,Dato); ImprimirLista(PtrInicio); Eliminar(&PtrInicio); ImprimirLista(PtrInicio); Contador(PtrInicio); getche(); }
int main() {FILE *fpi; char ch[10]; fpi=fopen("Input.txt","r"); FILE *fpo; fpo=fopen("Output.txt","w+"); if(fpi==NULL) return 0; while(!feof(fpi)) {fscanf(fpi,"%s",ch); fprintf(fpo,"%s",ch); printf("%s\n",ch); } fclose(fpi); fclose(fpo); getche(); }
/*********************************************************************//** * @brief Reads status register value * @param[in] SSPx SSP peripheral definition, should be: * - LPC_SSP0: SSP0 peripheral * - LPC_SSP1: SSP1 peripheral * @return None **********************************************************************/ void Read_Eeprom_Status (LPC_SSP_TypeDef *SSPx) { uint8_t wpen=0, bp1=0, bp0=0, wel=0, wip=0; uint8_t dat; clr_scr_rst_cur(LPC_UART0); dat = Ssp_Eeprom_Read_Status_Reg(SSPx); if(dat&0x80){wpen=1;}else{wpen=0;} if(dat&0x08){bp1 =1;}else{bp1 =0;} if(dat&0x04){bp0 =1;}else{bp0 =0;} if(dat&0x02){wel =1;}else{wel =0;} if(dat&0x01){wip =1;}else{wip =0;} print_status_reg(); printf(LPC_UART0,"\n\r%d01 X X X %d01 %d01 %d01 %d01\n\r",wpen,bp1,bp0,wel,wip); getche(LPC_UART0); EscFlag = 0; }
void main() { int a = 100; //var a initialised to 100. int*b = &a; //b is a pointer that holds the address of a. int**c = &b; //c is a double pointer that holds the address of b // which in turn holds the address of a clrscr(); printf("1. Value of a accessed through a(a): %d",a); printf("\n\n2. Value of a/value pointed to by b accessed through b(*b): %d",*b); printf("\n\n3. Address of a accessed through a(&a): %u",&a); printf("\n\n4. Address of a/value of b accessed through b(b): %u",b); printf("\n\n5. Address of b accessed through b(&b): %u",&b); printf("\n\n6. Address of b/value of c accessed through c(c): %u",c); printf("\n\n7. Value of b(which holds address of a) accessed through c(*c): %u",*c); printf("\n\n8. Value of a accessed through c(*(*c)): %d",*(*c)); printf("\n\n9. Address of c accessed through c(&c): %u",&c); getche(); }
void menu() { printf("階層型ニューラルネットワークの学習プログラム\n"); char c; do { printf("パターンのデータファイル[untitled.pdt]? "); scanf("%s", p_name ); printf("%s\n", *p_name); printf("結合荷重のデータファイル[untitled.wdt]? "); scanf("%s", w_name); printf("%s\n", *w_name); printf("seed値[1]? " ); scanf("%d", &seed ); printf("seed=%d\n", seed ); printf("よろしいですか(y/n)?"); c = getche(); } while ( c != 'y' && c != 'Y' ); }
void create() { do { newData = getNode(); if(start == NULL) { start = newData; } getData(newData); if(prev != NULL) { prev->next=newData; } prev=newData; printf("\n Want to add one more data[Y/N]:"); }while(getche()!='N'); }
int main() {int i,j; l=4; while(l!=-1) {Chopstick[l]=CreateSemaphore(NULL,1,1,NULL); l--; } printf("Enter the values of thinking and eating for five philosophers:\n"); for(i=0;i<5;i++) for(j=0;j<2;j++) scanf("%d",&TE[i][j]); HANDLE ThreadHandle[5]; DWORD ThreadId[5]; int Param[5]; l=4; while(l!=-1) {Param[l]=l; ThreadHandle[l]=CreateThread(NULL,0,Eat,&Param[l],0,&ThreadId[l]); l--; } l=4; while(l!=-1) { if(ThreadHandle[l]!=NULL) {WaitForSingleObject(ThreadHandle[l],INFINITE); CloseHandle(ThreadHandle[l]); } l--; } getche(); return 0; }
char * Sys_ConsoleInput ( void ) { static char text[256]; static int len = 0; char ch; if (!isDedicated) return NULL; if (! kbhit()) return NULL; ch = getche(); switch (ch) { case '\r': putch('\n'); if (len) { text[len] = 0; len = 0; return text; } break; case '\b': putch(' '); if (len) { len--; putch('\b'); } break; default: text[len] = ch; len = (len + 1) & 0xff; break; } return NULL; }
int insertCellphone(int line, int row, char *cellphone, int menu) { int valid, i, j, count = 0; gotoxy(line, row); for (i = 0, j = 0; i < 13;){ if (i == 3 || i == 8){ cellphone[i] = '-'; i++; j += 2; } else { gotoxy(line + i + j, row); cellphone[i] = getche(); if (i != 0 && cellphone[i] == 8){ if (i == 4 || i == 9){ printf(" \b\b"); i -= 2; j -= 2; gotoxy(line + i + j, row); printf(" \b\b"); } else{ i--; printf(" \b\b"); } } else{ valid = validCellphone(cellphone[i]); if (valid == 0) i++; else return -1; } } } validCellphoneErrorOff(); if (valid != -1){ valid = inputInfoYesOrNo(menu); if (valid == 0) cellphone[i] = '\0'; else valid = -2; gotoxy(0, 26); lineClear(); gotoxy(0, 28); lineClear(); } return valid; }
CAMLprim value sys_getch( value b ) { # ifdef _WIN32 return Val_int( Bool_val(b)?getche():getch() ); # else // took some time to figure out how to do that // without relying on ncurses, which clear the // terminal on initscr() int c; struct termios term, old; tcgetattr(fileno(stdin), &old); term = old; cfmakeraw(&term); tcsetattr(fileno(stdin), 0, &term); c = getchar(); tcsetattr(fileno(stdin), 0, &old); if( Bool_val(b) ) fputc(c,stdout); return Val_int(c); # endif }
void main() { int more=1,d=0, num=-1,a=0; st.top = -1; printf("Do you want to do Stack Operations: Enter 1 for YES 2 for NO:\n"); scanf("%d", &d); if(1==d) { while(more) { printf("\n Enter one of the following choices \n\n 1. For Pushing an element onto Stack\ \n 2. For Popping an element from the Stack\ \n 3. For Printing the Stack \n:"); scanf("%d", &d); switch(d) { case 1: push(); break; case 2: num = pop(); if(-1 == num) printf("\nPop operation FAILED \n"); break; case 3: printStack(); break; default: printf("\n You have not entered a valid choice \n"); break; } printf("\nDo you want to do one more operation: Enter 1 for YES 2 for NO:"); scanf("%d", &a); if(2 == a) more=0; else more=1; } } printf(" Do one more key press to Exit\n"); getche(); }
void DataKaryawan() { do { do { textcolor(LIGHTGREEN); clrscr(); gotoxy(28,2);printf(" DATA KARYAWAN "); gotoxy(28,3);printf(" Menu Pilihan "); gotoxy(28,4);printf("========================"); gotoxy(28,6);printf("1. Tambah Data "); gotoxy(28,7);printf("2. Tampil Data "); gotoxy(28,8);printf("3. Cari Data "); gotoxy(28,9);printf("4. Ubah Data "); gotoxy(28,10);printf("5. Hapus Data "); gotoxy(28,11);printf("6. Kembali "); gotoxy(28,13);printf("========================"); gotoxy(28,14);printf(" Pilihan [1..6] = ");scanf("%i", &menu); switch(menu) { case 1:tambahDTK();break; case 2:tampilDTK();break; case 3:cari1();break; case 4:ubahDTK();break; case 5:hapusDTK();break; case 6:Menu_Utama();break; } if((menu<=0)||(menu>6)) { gotoxy(24,15);textcolor(LIGHTRED); printf("Salah memasukkan pilihan! Ulangi!"); gotoxy(26,16);textcolor(15); printf("Tekan Enter Untuk Melanjutkan"); getch(); } }while((menu<=0)||(menu>6)); printf("\n\n\n"); printf("\t\t Tekan M untuk kembali ke Menu Data Karyawan = "); kmbli_menu=getche(); }while((kmbli_menu=='M')||(kmbli_menu=='m')); printf("\n\n"); }
void main() { int n, i; nodeptr j,q; char x,y; printf("Enter the number of nodes\n"); scanf("%d",&n); insert(list,n); printf("Linked List Created\n"); // printf("Linked list Created is:"); // display(); printf("Enter the item to be searched\n"); y=getche(); search(&list,y); getch(); }
char choice_system(void) { char optrtn; clrscr(); window(1,1,80,25); remakescreen_start(); screen_draw_start(); gotoxy(1,4); printf("[1] - HOSTEL Management System\n"); printf("[2] - FLAT Management System\n"); printf("[3] - EXIT\n"); gotoxy(1,25); cprintf("Please select an option...."); gotoxy(1,14); printf("Select an option: "); optrtn = getche(); return optrtn; }
void grade()//成绩记录函数 { system("cls"); int i = 0; char s; if ((fp = fopen("f:\\贪吃蛇\\贪吃蛇.txt", "ar")) == NULL)//打开文件 { printf("\nCannot open file!\n"); exit(0); } if (i<S)i = S; color(14); fwrite(&i, sizeof(i), 1, fp); fclose(fp); printf("最高的分为:%d\n\n", i); printf("\t按1返回\n\n"); printf("\t按2退出\n\n"); s = getche(); switch (s) { case '1':boundary(); break; case '2': end(); break; } }
/** * \brief Solicita un caracter al usuario y lo valida * \param input Se carga el caracter ingresado * \param message Es el mensaje a ser mostrado * \param eMessage Es el mensaje a ser mostrado en caso de error * \param lowLimit Limite inferior a validar * \param hiLimit Limite superior a validar * \return Si obtuvo el caracter [0] si no [-1] * */ int getChar(char* input,char message[],char eMessage[], char lowLimit, char hiLimit) { char aux; printf("%s", message); aux = toupper(getche()); if(aux < toupper(lowLimit) || aux > toupper(hiLimit)) { printf("%s", eMessage); return -1; } else { *input = aux; return 0; } }
/*-------------------------------------------------------------- | FUNCION: leerOpcionValida() | |--------------------------------------------------------------- | RESEÑA: muestra un mensaje al usuario solicitando un | | valor entero, | | | | DEVUELVE: opción seleccionada | --------------------------------------------------------------*/ int leerOpcionValida(char *mensaje, char num) { int opcion; printf("%s", mensaje); fflush(stdin); do{ printf("\b"); // el cursor retrocede una posicion opcion = getche(); // lee un caracter opcion = toupper(opcion); // pasa a mayúsculas el caracter leído if(opcion==13) { // retorno de carro printf("\b"); printf("%s", mensaje); } } while( (opcion<'0') || (opcion>num) ); printf("\n"); return opcion-48; }
int main() { char num; do { printf("\nDame numero"); num=getche(); if(num=='1') printf("\nuno"); else if(num=='2') printf("\ndos"); else if(num=='3') printf("\ntres"); } while(num!='s'); return 0; }
void menu() { printf("-------------------------MENU-------------------------\n"); printf("\n"); //printf("0 ) Ana Menu\n"); printf("1 ) En C*k Gol Atilan Devre\n"); printf("2 ) Gol Kralligi\n"); printf("3 ) Puan Durumu\n"); printf("4 ) Hattrick\n"); printf("5 ) Kendi Kalesine Atilan Goller\n"); printf("9 ) Cikis\n"); tercih = getche(); switch (tercih) { case '1': system("cls"); encokgol(); break; case '2': system("cls"); golkralligi(); break; case '3': system("cls"); puandurumu(); break; case '4': system("cls"); hattrick(); break; case '5': system("cls"); kendikalesine(); break; case '9': system("cls"); cikis(); break; default: system("cls"); menu(); break; }//switch }//void menu
void main() { FILE *p; char c; if ( (p = fopen ("prueba","w") ) == NULL) { PRS ("Error en apertura\n"); getch(); exit(1); } PRS("De caracteres...<R> para terminar."); while ( (c=getche()) != 13) fputc (c,p); if (fclose (p) == EOF) { PRS("Error al cerrar el archivo"); getch(); exit (1); } }
int __fill_buffer( FILE *fp ) { if( _FP_BASE( fp ) == NULL ) { __ioalloc( fp ); } if( fp->_flag & _ISTTY ) { /* 20-aug-90 */ if( fp->_flag & (_IONBF | _IOLBF) ) { __flushall( _ISTTY ); /* flush all TTY output */ } } fp->_flag &= ~_UNGET; /* 10-mar-90 */ fp->_ptr = _FP_BASE( fp ); #ifdef __UNIX__ fp->_cnt = __qread( fileno( fp ), fp->_ptr, (fp->_flag & _IONBF) ? 1 : fp->_bufsize ); #else if(( fp->_flag & (_IONBF | _ISTTY)) == (_IONBF | _ISTTY) && ( fileno( fp ) == STDIN_FILENO )) { int c; /* JBS 31-may-91 */ fp->_cnt = 0; c = getche(); if( c != EOF ) { *fp->_ptr = c; fp->_cnt = 1; } } else { fp->_cnt = __qread( fileno( fp ), fp->_ptr, (fp->_flag & _IONBF) ? 1 : fp->_bufsize ); } #endif if( fp->_cnt <= 0 ) { if( fp->_cnt == 0 ) { fp->_flag |= _EOF; } else { fp->_flag |= _SFERR; fp->_cnt = 0; } } return( fp->_cnt ); }
void main() { int randumday; char ceapgoing='y'; srand(time(NULL)); while (ceapgoing=='y'||ceapgoing=='Y') { randumday=rand()%(Sat+1); switch(randumday) { case Sun: cout<<"Sunday"<<endl; break; case Mon: cout<<"Monday"<<endl; break; case Tue: cout<<"Tuesday"<<endl; break; case Wed: cout<<"Wenday"<<endl; break; case Thr: cout<<"Thursday"<<endl; break; case Fry: cout<<"Fryday"<<endl; break; case Sat: cout<<"Saturday"<<endl; break; default: cout<<"Error"<<endl; } cout<<"Keep going"<<endl; ceapgoing=char(getche()); cout<<endl; } }
void main() { int pil; atas://label titik kembali clrscr(); printf("=========================== \n"); printf(" MENU UTAMA \n"); printf("=========================== \n"); printf("1. Hitung Luas Segi 3 \n"); printf("2. Hitung Luas Segi 4 \n"); printf("3. Penjualan \n"); printf("0. Selesai \n"); printf("=========================== \n"); printf(" Pilihan [0 = 3 ]:");scanf("%i",&pil); if(pil==1){segi3();goto atas;} else if(pil==2){segi4();goto atas;} else if(pil==3){jual();goto atas;} else if(pil==0){goto bawah;} else {goto atas;} bawah: getche();}
int main() { float *nums; int i,aux,n = 0; printf("Ola, voce deseja calcular a media e mediana de quantos numeros?\n"); scanf("%d",&n); aux = n; n *= sizeof(*nums); nums = (float*)malloc(n); for (i = 0;i < aux;i++) { printf("Por favor digite o %d numero\n",i+1); scanf("%f",&*(nums+i)); } printf("Media: %.2f\nMediana: %.2f\n",media(nums,n),mediana(nums,n)); free(nums); getche(); return 0; }