// La fonction main int main(void) { int choix; // Construction et remplissage de la matrice do{ printf("======================================================================.\n"); printf("CE PROGRAMME CALCUL LE DETERMINANT D'UNE MATRICE SAISIE AU CLAVIER.\n"); printf("======================================================================.\n"); int n = getDim(); float A[n][n]; int i, j; printf("\n"); for(i = 0; i < n; i++){ for (j = 0; j < n; j++){ printf("Entrer l'element de %d ligne et de la %d colonne : ", i + 1, j + 1); scanf("%f", &A[i][j]); } } printf("\nLe determinant de votre matrice est : %.2f", determinant(n, A)); printf("\n\n======================================================================.\n"); printf("\nEntrer q pour quiter le programme.\n"); printf("Entrer n'importe quoi pour recommencer.\n"); printf("\nVoulez-vous recommencer : "); clean_stdin(); scanf("%d", &choix); clean_stdin(); system("cls"); }while(choix != 0); system("cls"); printf("\n\nAU REVOIR !.\n\n\n\n\n\n\n\n"); return 0; }
void text() { char d[23]; printf("Enter the name of field:"); scanf("%s",name); clean_stdin(); printf("Enter any default value:"); scanf("%s",d); clean_stdin(); fprintf(f,"<tr> \n <td>%s</td> \n <td><input type=text name=%s value=%s></td></tr>\n",name,name,d); }
void password() { printf("Enter the name of field:"); scanf("%s",name); clean_stdin(); fprintf(f,"<tr> \n <td>%s</td> \n <td><input type=password name=%s></td></tr>\n",name,name); }
void checkbox() { int oc,j; printf("Enter the Heading of field:"); scanf("%s",name); clean_stdin(); fprintf(f,"<tr> \n<td>%s</td>\n",name); printf("How many options:"); scanf("%d",&oc); clean_stdin(); for(j=1; j<=oc; j++) { printf("Enter the %d option:",j); scanf("%s",option); clean_stdin(); fprintf(f,"<td><input type=checkbox name=%s value=%s>%s</td>\n",name,option,option); } fprintf(f,"</tr>\n"); }
int saisiNbPlace() { int n; char c; do { printf("Veuillez saisir le nombre de place que vous souhaitez réserver (entre %d et %d) : ", NB_PLACES_MIN, NB_PLACES_MAX); } while(((scanf("%d%c",&n, &c)!=2 || c!='\n') && clean_stdin()) || n < NB_PLACES_MIN || n > NB_PLACES_MAX); return n; }
int capChar(char* message) { int date; char c; do { printf("Veuillez saisir %s : ", message); } while(((scanf("%d%c",&date, &c)!=2 || c!='\n') && clean_stdin())); return date; }
int main(void) { int num1 = 0; int num2 = 0; char c; do { printf("\nIngresa un numero: "); } while (((scanf("%d%c", &num1, &c)!=2 || c!='\n') && clean_stdin())); //Mientras el scanf no lea 2 caracteres //(entero + \n) o el caracter leido no sea '\n', va a repetir la linea dentro del do. Ademas, limpia el stdin //Solo si no lee 2 caracteres (entero + \n) o el segundo caracter no es \n. do { printf("\nIngresa un numero: "); } while (((scanf("%d%c", &num2, &c)!=2 || c!='\n') && clean_stdin())); printf("Suma: %d\n", num1+num2); return 0; }
int getDim(){ //demande a l'utilisateur un entier positif comme dimension de la matrice int dim; int essaie = 0; do{ if (essaie == 0){ printf("\nEnter la dimension de la matrice : "); essaie++; }else{ printf("\nVous devez entrer un entier positif\nEnter la dimension de la matrice : "); } }while (((scanf("%d", &dim)!=1) && clean_stdin()) || dim < 0); return dim; }
void broadcast(pid_t server_id, int idShm) { char *message; char buff[SHARED_MEM_SIZE]; message = (char*) shmat(idShm, NULL, 0); Trace("\nMessage a diffuser: "); clean_stdin(); fgets(buff, SHARED_MEM_SIZE, stdin); strcpy(message, buff); shmdt(message); kill(server_id, SIGUSR2); }
void main() { f=fopen("onform.html","w"); int i,n; printf("Enter the title for your html file:"); scanf("%s", title); printf("Enter the css file to be used:"); scanf("%s",css); printf("Enter the name of script file to be executed:"); scanf("%s",script); printf("How many fields you want in your table:"); scanf("%d",&n); clean_stdin(); //fprintf for writing the things in html file fprintf(f,"<html><head> \n <title>%s</title>",title); fprintf(f,"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"> \n </head><body>\n",css); fprintf(f,"<header><h1>%s</h1></header>",title); fprintf(f,"<table>"); fprintf(f, "<form action=\"%s\" method=\"GET\">",script); for(i=0; i<n; i++) { printf("Enter the type of field:"); scanf("%c",&type); if(type=='t') { text(); } else if(type=='r') { radio(); } else if(type=='c') { checkbox(); } else if(type=='p') { password(); } } fprintf(f,"</table>"); fprintf(f,"<center><input type=submit value=Submit></center>"); fprintf(f,"</form></body></html>"); }
int read_command() { int total_bytes_read = bytes_in_buffer; int bytes_read = 0; int last_read_byte_pos = 0; while (true) { int end_of_line = find_end_of_line(helper_buffer, last_read_byte_pos, total_bytes_read); if (end_of_line == -1) { if (total_bytes_read > MAX_LINE_LENGTH) { bytes_in_buffer = 0; if (helper_buffer[bytes_read - 1]) { clean_stdin(); } fprintf(stderr, "%s\n", SYNTAX_ERROR_STR); fflush(stderr); return 0; } } else { bytes_in_buffer = total_bytes_read - end_of_line - 1; if (end_of_line > MAX_LINE_LENGTH) { fprintf(stderr, "%s\n", SYNTAX_ERROR_STR); fflush(stderr); bytes_read = 0; } else { prepare_line_buffer(line_buffer, helper_buffer, end_of_line); bytes_read = end_of_line; } clean_helepr_buffer(helper_buffer, end_of_line + 1, bytes_in_buffer); return bytes_read; } bytes_read = read(STDIN_FILENO, helper_buffer + total_bytes_read, MAX_LINE_LENGTH + 1); if (bytes_read == 0) { was_end_of_file = true; return 0; } else if (bytes_read == -1) { bytes_read = 0; continue; } last_read_byte_pos = total_bytes_read; total_bytes_read += bytes_read; } }
/*********************************************** Method: p2p_client_app Description: Main application logic loop ***********************************************/ void p2p_client_app ( void ) { char input; /*---------------------------------------- Display menu and act on user input ----------------------------------------*/ while(1) { display_menu(); input = getc(stdin); clean_stdin(); p2p_client_parse_op(input); } }
// Get a choice from user given array of suitable integers int getintchoice(char *greet, int choices[], int opns) { int chosen = 0; int selected = 0; int i; printf("\nChoice: %s\n",greet); do { //Get user choice char c; do { printf("Enter choice: "); } while (((scanf("%d%c", &selected, &c)!=2 || c!='\n') && clean_stdin()) || selected<1 || selected>99999); printf("'%d' selected.\n", selected); for (i = 0; i < opns; i++) { if(selected == choices[i]) { chosen = 1; break; } } if(!chosen) { printf("Incorrect choice, select again.\n"); printf("Options include the following:\n"); for (i = 0; i < opns; i++) { printf("%d ",choices[i]); } printf("\n"); } } while(!chosen); return selected; }
int main(int argc, char *argv[]) { Graph *g; int test_num; char continue_run; char rebuild_graph; char *path = (char *)malloc(256 * sizeof(char)); int opt; while((opt = getopt(argc, argv, "p:")) > 0) { switch(opt) { case 'p': g = init_graph_from_file(optarg); break; default: break; } } printf("Enter test unit? y or n: "); scanf("%c", &continue_run); clean_stdin(); while(continue_run == 'y' || continue_run == 'Y') { printf("Need rebuild graph? y or n: "); scanf("%c", &rebuild_graph); clean_stdin(); if(rebuild_graph == 'y' || rebuild_graph == 'Y') { size_t n = 255; int byte_read; printf("Input source file path: "); byte_read = getline(&path, &n, stdin); if(byte_read == -1) { printf("ERROR"); } if(path[byte_read-1] == '\n') path[byte_read-1] = '\0'; if(g != NULL) destroy(g); g = init_graph_from_file(path); } if(g == NULL) { printf("The test graph is NULL\n"); exit(EXIT_FAILURE); } printf("Input a number to choose test functions: "); scanf("%d", &test_num); clean_stdin(); switch(test_num) { case 0: print_graph(g); break; case 1: test_dfs(g); break; case 2: test_bfs(g); break; case 3: test_top_sort(g); break; case 4: test_strong_component(g); break; case 5: print_reverse_graph(g); break; default: break; } printf("Continue test? y or n: "); scanf("%c", &continue_run); clean_stdin(); } if(path != NULL) free(path); destroy(g); return 0; }
int main(void) { int choice = 0, lastOpe = 0; unsigned long fact = 0; char *str = NULL; BigInteger biOne = NULL, biTwo = NULL, res = NULL, temp = NULL; do { choice = display_menu(); switch(choice) { case 1: clean_stdin(); str = new_str_of_big_int(1); biOne = newBigInteger(str); free(str); str = NULL; break; case 2: clean_stdin(); str = new_str_of_big_int(2); biTwo = newBigInteger(str); free(str); str = NULL; break; case 3: temp = fromBigIntegerToBigInteger(biOne); biOne = fromBigIntegerToBigInteger(biTwo); biTwo = fromBigIntegerToBigInteger(temp); break; case 4: lastOpe = '+'; res = sumBigInt(biOne, biTwo); break; case 5: lastOpe = '-'; res = diffBigInt(biOne, biTwo); break; case 6: lastOpe = '*'; res = mulBigInt(biOne, biTwo); break; case 7: printf("Enter the number :\t"); scanf("%lu", &fact); res = factorial(fact); printf("(%ld)! = ", fact); printBigInteger(res); break; case 8: printf("BigInteger 1 :\t"); printBigInteger(biOne); printf("BigInteger 2:\t"); printBigInteger(biTwo); if(lastOpe != 0) { printf("\n(1) %c (2) = ", lastOpe); printBigInteger(res); } break; } printf("\n"); }while (choice != 9); delete_big_int(biOne); delete_big_int(biTwo); delete_big_int(res); delete_big_int(temp); return 0; }
int main( int argc, char *argv[] ) { system("clear"); char * mensaje = (char *) malloc(sizeof(char*)*100); char * senha = (char *) malloc(sizeof(char*)*100); int opc = 0; printf("Enter para iniciar!"); while (opc != 3) { clean_stdin(); printf("\nSelecciona la operación a realizar: "); printf("\n(1) Cifrar mensaje"); printf("\n(2) Descifrar mensaje"); printf("\n(3) Salir\n"); scanf("%d", &opc); switch(opc) { case 1: clean_stdin(); printf("Introduce el mensaje (máximo 100 caracteres)\n"); fgets(mensaje, 100, stdin); printf("\nIntroduce la contraseña (menor que el mensaje)\n"); fgets(senha, 100, stdin); if ((strlen(mensaje)>0) && (mensaje[strlen (mensaje) - 1] == '\n')) mensaje[strlen (mensaje) - 1] = '\0'; if ((strlen(senha)>0) && (senha[strlen (senha) - 1] == '\n')) senha[strlen (senha) - 1] = '\0'; senha = validarSenha(senha, mensaje); if(senha == NULL) printf("ERROR: Tu contraseña es más grande que el texto\n"); char * cifrado = (char *) malloc(sizeof(char*)*strlen(mensaje)); printf("\n\n******************Cifrando*******************\n\n"); strcpy(cifrado, cifrar(senha, mensaje)); printf("Tu mensaje cifrado es:\n%s\n\nPresiona cualquier tecla para continuar", cifrado); clean_stdin(); break; case 2: clean_stdin(); printf("Introduce el mensaje (máximo 100 caracteres)\n"); fgets(mensaje, 100, stdin); printf("\nIntroduce la contraseña (menor que el mensaje)\n"); fgets(senha, 100, stdin); if ((strlen(mensaje)>0) && (mensaje[strlen (mensaje) - 1] == '\n')) mensaje[strlen (mensaje) - 1] = '\0'; if ((strlen(senha)>0) && (senha[strlen (senha) - 1] == '\n')) senha[strlen (senha) - 1] = '\0'; senha = validarSenha(senha, mensaje); if(senha == NULL) printf("ERROR: Tu contraseña es más grande que el texto\n"); char * descifrado = (char *) malloc(sizeof(char*)*strlen(mensaje)); printf("\n\n******************Descifrando*******************\n\n"); strcpy(descifrado, descifrar(senha, cifrado)); printf("Tu mensaje descifrado es:\n%s\n\nPresiona cualquier tecla para continuar", descifrado); clean_stdin(); break; case 3: break; default: printf("\nOpción incorrecta\n"); pause(); break; } } return 0; }