Exemplo n.º 1
0
int main(void)
{
    const unsigned int SIZE = 128;
    char str[SIZE];
    char ch;

    do
    {
        puts("Input a string:");
        __fpurge(stdin);
        fgets(str, SIZE, stdin);
        str[strlen(str) - 1] = '\0';

        puts("After Reverse:");
        reverse_string(str);
        puts(str);
        
        puts("Enter any key except q to go on.");
        __fpurge(stdin);
        ch = getchar();
    } while (ch != 'q');

    return 0;
}
Exemplo n.º 2
0
gboolean confirm_delete(recent_file_options_t* options)
{
  char option;
  static char yes = 'y';
  static char no = 'n';

  if (options->force)
    return TRUE;

  if (!options->quiet)
    printf ("Are you sure you want to clear recent files (%c/%c) ", yes, no);

  option = tolower(getchar());
  __fpurge(stdin);
  while ( (option != yes) && (option != no) )
    {
      if (!options->quiet)
	printf ("Please press %c or %c\n", yes, no);
      while (getchar()!='\n');
      option = tolower(getchar());
      __fpurge(stdin);
    }
  return (option == yes);
}
Exemplo n.º 3
0
peo_p input_data(peo_p *newnode)
{
    system("clear");
    printf("\n\n请输入好友名字:\n");
    __fpurge(stdin);                             //删除缓存区内容
    scanf("%s", (*newnode)->name);
   
    printf("\n请输入好友手机号码:\n");
    __fpurge(stdin);                             //删除缓存区内容
    scanf("%s", (*newnode)->cell);
    
    printf("\n请输入好友地址:\n");
    __fpurge(stdin);                             //删除缓存区内容
    scanf("%s", (*newnode)->adress);

    printf("\n请输入好友公司电话号码:\n");
    __fpurge(stdin);                             //删除缓存区内容
    scanf("%s", (*newnode)->company_tel);

    print_n_ch('=', 60);
    printf("\n");

    return *newnode;
}
Exemplo n.º 4
0
int main(int argc, const char **argv){

    int resultado=0;
    int ancho=0;
    int buffer=0;

    struct TMatriz matriz;

    inicio (&matriz);

    // Preguntar al usuario.

    do{
	__fpurge(stdin);
	printf ("Cuantas filas quiere que tenga su matriz?\n");
	scanf ("%i", &matriz.filas);
	printf ("Cuantas columnas quiere que tenga su matriz?\n");
	scanf ("%i", &matriz.col);
    }while(matriz.filas == 0 && matriz.col == 0);

    // reservar espacio para a

    matriz.a = (int *) realloc (matriz.a, ((matriz.filas)*(matriz.col)*sizeof(int)));

    ancho = matriz.col;

    for (int f=0; f<matriz.filas; f++)
	for (int c=0; c<matriz.col; c++){
	    printf("(%i, %i)", f+1, c+1);
	    scanf(" %i", &buffer);
	    set(matriz.a, f, ancho, c, buffer);
	}

    printf ("Ahora imprimiremos tu matriz\n");
    for (int f=0; f<matriz.filas; f++){
	for(int c=0; c<matriz.col; c++){
	    resultado = get(matriz.a, f, ancho, c);
	    printf ("%4i", resultado);
	}
	printf ("\n");
    }

    // Liberar espacio para a

    free(matriz.a);

    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
/************************************************ 
 * entrada_dados                                *
 * objetivo: rotina para ler dados              *
 * entrada : nodo (ponteiro para o novo espaco) *
 * saida   : nodo com dados                     *
 ************************************************/
void entrada_dados( PILHA* aux )
{ 
    printf( "\n\n Digite a matricula: " ); 
    __fpurge(stdin);
    fflush( stdin );     // limpa buffer do teclado, funciona junto com entrada de dados
    scanf("%d", &aux->info.matr);

/*
    printf( "\n Digite o nome: " );
    __fpurge(stdin);
    fflush( stdin );     // limpa buffer do teclado, funciona junto com entrada de dados
    gets( aux->info.nome );
*/  
    aux->prox= NULL;     // n�o aponta

}
Exemplo n.º 6
0
int main() {
	int cases;
	scanf("%d", &cases);

	while (cases--) {
		scanf("%d %d", &height, &width); __fpurge();
		char** board = new char*[height];
		for (int i = 0; i < height; i++) board[i] = new char[width];
		for (int i = 0; i < height; i++) {
			char buf[1024]; fgets(buf, 1024, stdin);
			strncpy(board[i], buf, width);
		}
		int countOfValidPath = get_countOfValidPath(board);
		printf("%d\n", countOfValidPath);
	}
}
Exemplo n.º 7
0
int main() {
	struct automobil A[MAX]; //niz automobila
	int n; //dužina niza
	int maxKub; //maksimalna dozvoljena kubikaža
	int max, maxI;
	int i;

	printf("Unesite broj automobila [n<=%d]: ", MAX);
	do {
		scanf("%d", &n);
	} while (n <= 0 || n > MAX);

	//Učitavanje niza
	for (i = 0; i < n; i++) {
		printf("Unesite marku automobila br. %d: ", i + 1);
		__fpurge(stdin);
		gets(A[i].marka);
		do {
			printf("Unesite kubikazu automobila br. %d: ", i + 1);
			scanf("%d", &A[i].kub);
		} while (A[i].kub <= 0);
		do {
			printf("Unesite godiste automobila br. %d: ", i + 1);
			scanf("%d", &A[i].god);
		} while (A[i].god < 1886); //'86 je napravljen prvi automobil, pa ne može biti mlađi od toga
	}

	printf("Unesite maksimalnu kubikazu: ");
	scanf("%d", &maxKub);

	//Traženje najnovijeg automobila
	max = 0; //sve kubikaže moraju biti veće od nule
	for (i = 0; i < n; i++) {
		if (A[i].kub < maxKub) {
			if (A[i].god > max) {
				max = A[i].god;
				maxI = i;
			}
		}
	}

	//Ispis traženog automobila
	printf("Najnoviji automobil koji zadovoljava uslove je:\n");
	printf("Marka: %s\nKubikaza:%d\nGodiste:%d\n", A[maxI].marka, A[maxI].kub, A[maxI].god);

	return 0;
}
Exemplo n.º 8
0
/*-----------------------------ReadStdin------------------------------*/
static void ReadStdin(struct ev_loop *loop, ev_io *w, int revents) {
	char 		result[BUFFSIZE];
	char 		new_string[BUFFSIZE];

    LogDebug("%s ReadStdin Fired ", global_argv[0]);
    __fpurge(stdin);
    fflush(stdout);
	fgets(new_string, BUFFSIZE, stdin);

	// Processing input from stdin
	sprintf(result, "%s", new_string);
	STDIN_to_Socket(sockfd, result, strlen(result));


	memset( (void *)&result, '\0', sizeof(result)); 
	memset( (void *)&new_string, '\0', sizeof(new_string)); 
}
Exemplo n.º 9
0
void print_eating() {
    int i;
    int eat = 0;
    printf("Philosopher(s) ");
    for (i = 0; i < NUM_CHOPSTICKS; i++) {
        if (chopsticks[i] == i && chopsticks[i + 1] == i) {
            printf("%i ", i);
            eat = 1;
        }
    }
    if (eat == 1) {
        printf("are eating\n");
    }
    else {
        __fpurge(stdout);
    }
}
Exemplo n.º 10
0
void telaInserir(reg* registros) {
    char nome[50];
    float nota1, nota2;
    
	system("clear");
	printf("\n\nInforme nome: ");
	scanf("%s", nome);
	printf("Informe a nota 1: ");
	scanf("%f", &nota1);
	printf("Informe a nota 2: ");
	scanf("%f", &nota2);

    inserir(registros, nome, nota1, nota2);
    
	__fpurge(stdin);
	getchar();
}
Exemplo n.º 11
0
Arquivo: kohi.c Projeto: ksysctl/kohi
/* Sets terminal's text color.
 */
void textcolor(const int color_)
{
	__fpurge(stdin);
	__color = color_;

	if ((__color >= 0) && (__color <= 7))
	{
		printf("\033[0;3%d;4%dm",__color,__background);
	}
	else
	{
		if ((__color >= 10) && (__color <= 17))
			printf("\033[1;3%d;4%dm",(__color - 10),__background);
		else
			printf("\033[0;3%d;4%dm",RESET_COLOR,__background);
	}
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: igoraresti/C
void main(){
    
    char frase[50];
    
    printf("\nIntroduce una frase o palabra: ");
    fflush(stdout);
    __fpurge(stdin);
    fgets(frase,50,stdin);
    
    EliminaCaracteresNoAlfabeticos(frase);
    
    PasaTodoAMayusculas(frase);
    
    CompruebaSiEsPalindromo(frase);
    
    
}
Exemplo n.º 13
0
char *readLine(int maxlength) {
	char *str = (char *) malloc(sizeof(char) * (maxlength + 1));
	int i;
	// str (char *)
	//   |
	//   -----> "a"
	//          "a"
	//          "a"
	//          "\0"   maxlength = 3

	for (i = 0; i < maxlength && (str[i] = fgetc(stdin)) != ENTER; i++);
	for (; i < maxlength; i++) str[i] = ' ';
	str[i] = '\0';

	__fpurge(stdin);

	return str;
}
Exemplo n.º 14
0
int main(){
  Nodo *head=NULL;
  int valore;
  FILE *src=fopen("base", "r");

  while(fscanf(src, "%d", &valore) != EOF)
    Inserimento(&head, valore);

  Modifica(head);

  while(head){
    printf("%3d ", head->valore);
    head=head->next;
  }

  __fpurge(stdin);
  getchar();
}
Exemplo n.º 15
0
int get_option()
{
    int option = 0;

    do
    {
        puts("Enter a number to choose an option:");
        puts("1.Displayed by original order");
        puts("2.Displayed by ASCII");
        puts("3.Displayed by string length descending");
        puts("4.Displayed by the first word length");
        puts("5.Re-enter a set of strings");
        puts("6.Quit");
        __fpurge(stdin);
    } while (1 != scanf("%d", &option) || option < 1 || option > 6);

    return option;
}
Exemplo n.º 16
0
void* th_main(void* th_main_args) {
    int i;
    int deadlock = -1;

    //printf("th_main\n");

    for (i = 0; i < NUM_CHOPSTICKS; i++) {
        chopsticks[i] = -1;
        deadlock_condition[i] = i;
    }

    for (i = 0; i < NUM_PHILOSPHERS; i++) {

        if (pthread_create(&philosphers[i], NULL, th_phil, i)) {
            perror("ERROR creating thread.");
            exit(1);
        }

    }

    while (TRUE) {
        //printf("DL INIT\n");
        deadlock = deadlock_check();

        if (deadlock == 0) {
            perror("Deadlock condition (0,1,2,3,4) ... terminating\n");
            break;
        }

        print_eating();__fpurge(stdout);
    }

    for (i = 0; i < NUM_PHILOSPHERS; i++) {
        pthread_kill(&philosphers[i], 9);

    }
    pthread_exit(0);

    return(0);



} // end th_main function
Exemplo n.º 17
0
void studentDelete(student * source)
{
    puts("Choose the student you want to remove from the list");
    for (int i=0; i<studentCount; i++)
        printf("%d - %s %s %s\n\n",i+1,source[i].personal.firstName,source[i].personal.secondName,source[i].personal.lastName);
    int inp;
    while(1)
    {
    printf("Your choise: ");
    __fpurge(stdin);
    if (!scanf("%d",&inp)) { puts("Input Error"); continue; }
    if (inp<1 || inp >=studentCount) { puts("Input Error"); continue; }
    break;
    }
    int validIndex = inp-1;
    for (int i = validIndex; i<=studentCount; i++)
        source[i]=source[i+1];
    studentCount--;
}
Exemplo n.º 18
0
int menu_print()
{
    int choisen_menu_number;  /* 선택된 메뉴번호를 저장하는 변수 */

    main_list = loading_data_file(main_list); /* 기본 데이터 파일인 "book.dbf"을 부른다. */
        
    while(1)                    /* 메뉴는 종료를 선택할 때까지 반복해서 출력된다. */
    {
        putchar('\n');
        printf("1.  Insert\n");
        printf("2.  List\n");
        printf("3.  Save as a data file\n");
        printf("4.  Quit\n\n");
        printf("Enter the number : ");

        choisen_menu_number = getchar(); /* 메뉴 번호를 아스키코드로 받는다. */
        __fpurge(stdin);                 /* 버퍼를 비워 준다. */
        
        switch(choisen_menu_number)
        {
        case '1':                     /* 책을 연속적으로 추가하는 기능을 기본으로 한다. */
            insert_book();
            break;

        case '2':
            print_list_books(); /* 입력된 도서목록을 출력하며 책 추가 기능과 삭제 기능이 있다. */
            break;

        case '3':
            writing_data_file(main_list);
            break;

        case '4':
            printf("Thanks for using. See you again.\n");
            exit(-1);
            

        default:                /* 사용자가 지정된 키 이외의 입력을 했을 경우 에러 메세지 출력 후 다시 메뉴를 출력. */
            printf("You enter the wrong number.\n");
        }
    }    
    return choisen_menu_number;
}
Exemplo n.º 19
0
int main()
{	
    //initscr(); 	
	n_enemies=0;
	srand(time(NULL));
	player.x=rand()%MAXLIN;
    player.y=rand()%MAXCOL; /*inicializa o player numa posição qualquer*/
    int temp_life,lvl=0;
    do{
    	int f;
    	if(kill==1)
    	{
    		kill=0;
    		n_enemies=10;
    		lvl=1;
    	}
		else
			n_enemies+=10;
			lvl++;
    	new_map_enemies();
        print_map();
        temp_life=1;
        do{
        	
			move_human();
			if(enable_mv==1)
			{
				move_enemies();
				print_map();
				temp_life=test_enemies();
				enable_mv=0;
			}
			        	        	
		}while(temp_life!=0 && master_quit==0 && kill==0);
		for(f=0;f<n_enemies;f++)
			robot[f].alive=0;		
	}while(master_quit==0);
	printf("\nLevel: %d", lvl);
	__fpurge(stdin);
	getchar();
	return EXIT_SUCCESS;
}
Exemplo n.º 20
0
enum TipoOpcion leer_menu() {
    int opcion;

    do {
        titulo(); // Invocar a la función título
        printf(
            "\n\n\tElige una opción: \n\n"
            "\t\t1.- Crear una sopa.\n"
            "\t\t2.- Abrir una sopa.\n"
            "\t\t3.- Guardar.\n"
            "\t\t4.- Ver la sopa activa.\n"
            "\t\t5.- Salir\n"
            "\n\tTu Opción: "
        );
        __fpurge(stdin);
        scanf(" %i", &opcion);
    } while(opcion<1 || opcion>salir+1);
    titulo();
    return (enum TipoOpcion) (opcion - 1);
}
Exemplo n.º 21
0
//RETORNA UMA MENSAGEM ACIMA DO TABULEIRO
int msg(int m)
{
    if (m==1)
    {
        CLEAR
        printf("**** MOVIMENTO INVALIDO! TENTE DE NOVO ****  Score: %d pontos   Movimentos: %d     \n",pontos,mov);
        imprimevetor();
        __fpurge(stdin);
        leitura();
    }
    else if (m==0)
    {
        CLEAR
        if(match)
            printf("****** PECA MOVIDA COM SUCESSO! *******   Score: %d pontos   Movimentos: %d     \n",pontos,mov);
        else
            printf("************ MULTIPLAS!!! *************   Score: %d pontos   Movimentos: %d     \n",pontos,mov);
        imprimevetor();
        leitura();
    }
Exemplo n.º 22
0
Arquivo: kohi.c Projeto: ksysctl/kohi
/* Gets a character from keyboard and print to the screen.
 */
char getche()
{
struct termios SET_STORED;
struct termios SET_NEW;
char c;

	tcgetattr(0, &SET_STORED);
	SET_NEW = SET_STORED;

	SET_NEW.c_lflag     = ~(ICANON);
	SET_NEW.c_cc[VTIME] = 0;
	SET_NEW.c_cc[VMIN]  = 1;

	tcsetattr(0, TCSANOW, &SET_NEW);
	__fpurge(stdin);
	c = getchar();
	tcsetattr(0, TCSANOW, &SET_STORED);

return c;
}
Exemplo n.º 23
0
int main(void)
{
        printf("REGISTRO DE HABITANTES E MEDIA SALARIAL\n\n");

        /* vars */
        float mediaSalarial = 0;
        struct habitante habitantes[QTD_HABITANTES];

        /* Entrada */
        for (int i = 0; i < QTD_HABITANTES; i++) {
                printf("\nHabitante %i\n", i + 1);
                printf("Idade: ");
                scanf("%i", &habitantes[i].idade);

                printf("Sexo: ");
                __fpurge(stdin);
                scanf("%c", &habitantes[i].sexo);

                printf("Salario: ");
                scanf("%f", &habitantes[i].salario);

                printf("Filhos: ");
                scanf("%i", &habitantes[i].qtdFilhos);

                mediaSalarial += habitantes[i].salario;
        }

        mediaSalarial /= QTD_HABITANTES;

        /* Saída */
        printf("\nDADOS\n");
        for (int i = 0; i < QTD_HABITANTES; i++) {
                printf("\n----------\n");
                printf("Idade: %i\n", habitantes[i].idade);
                printf("Sexo: %c\n", habitantes[i].sexo);
                printf("Salario: R$ %.2f\n", habitantes[i].salario);
                printf("Filhos: %i\n", habitantes[i].qtdFilhos);
        }

        printf("\nMEDIA SALARIAL: R$%.2f\n", mediaSalarial);
}
Exemplo n.º 24
0
TEST(stdio_ext, __fpurge) {
  FILE* fp = tmpfile();

  ASSERT_EQ('a', fputc('a', fp));
  ASSERT_EQ(1U, __fpending(fp));
  __fpurge(fp);
  ASSERT_EQ(0U, __fpending(fp));

  ASSERT_EQ('b', fputc('b', fp));
  ASSERT_EQ('\n', fputc('\n', fp));
  ASSERT_EQ(2U, __fpending(fp));

  rewind(fp);

  char buf[16];
  char* s = fgets(buf, sizeof(buf), fp);
  ASSERT_TRUE(s != nullptr);
  ASSERT_STREQ("b\n", s);

  fclose(fp);
}
Exemplo n.º 25
0
Arquivo: main.c Projeto: igoraresti/C
void main()
{
    char letras;
    int distancia,bucle;
    
    printf("\nIntroduce una sucesion de caracteres que termine en punto, ademas,"
            "elige la distancia a la que quieres desplazar las letras: ");
    fflush(stdout);
    __fpurge(stdin);
    scanf("%d",&distancia);
    printf("\n");
    fflush(stdout);
    do
    {
        scanf("%c",&letras);
        if(letras>='a' && letras<='z'){
            letras=letras+distancia;
            if(letras>'z')
            {
                bucle=letras-'z';
                letras='a'-1+bucle;
            }
            printf("%c",letras);
        }
        
        if(letras>='A' && letras<='Z'){
            letras=letras+distancia;
            if(letras>'Z')
            {
                bucle=letras-122;
                letras='Z'-1+bucle;
            }
            printf("%c",letras);
        }
            
        
    }while(letras!='.');
    
    
}
Exemplo n.º 26
0
int main()
{
	int i,j,k,l;

	scanf("%d%d", &k, &l);
	__fpurge(stdin);
	if(k>l)
	{
		i=k;
		k=l;
		l=i;
	}
	
	for(i=k;i<=l;i++)
	{
		for(j=1;j<=9;j++)
		{
			printf("%d * %d = %d\n", i, j, i*j);
		}
		getchar();
	}
}	
Exemplo n.º 27
0
void* chat_write(int sockfd)

{
    while(1)
    {
        printf("%s",buf);
            fgets(buffer,MAXDATALEN-1,stdin);

          if(strlen(buffer)-1>sizeof(buffer)){
           printf("buffer size full\t enter within %d characters\n",sizeof(buffer));
           bzero(buffer,MAXDATALEN);
           __fpurge(stdin);
           }

        n=send(sockfd,buffer,strlen(buffer),0);

          if(strncmp(buffer,"quit",4)==0)
           exit(0);
           
         bzero(buffer,MAXDATALEN);
    }//while ends
}
Exemplo n.º 28
0
int main(int argc, const char **argv){
    int pila[N];
    int primera_pos_libre = 0;
    int entrada, salida;

    while(1){
        entrada = -1;
        printf(": ");
        scanf(" %i", &entrada);
        __fpurge(stdin);
        printf("entrada = %i\n", entrada);

        if (entrada < 0)
            salida = sacar(pila, &primera_pos_libre);
        else
            meter(entrada, pila, &primera_pos_libre);

        mostrar_estado(pila, primera_pos_libre, salida);
    }

    return EXIT_SUCCESS;
}
Exemplo n.º 29
0
void main_menu()
{
    int num;
    puts("Main menu. Choose a task:");
    puts("1. Translate inches to meters");
    puts("2. Calculation time of half way");
    puts("3. Definition of palindrome");
    puts("4. Play the circle game");
    puts("5. Inspection of phrases");
    puts("0. Exit");
    printf(">>> ");
    if (scanf("%d", &num) == 1)
    {
        switch (num)
        {
        case 0:
            break;
        case 1:
            menu_inch_to_cm(); break;
        case 2:
            menu_time(); break;
        case 3:
            menu_palindrome(); break;
        case 4:
            menu_circle_game(); break;
        case 5:
            menu_phrases(); break;
        default:
            puts("Error! Invalid number.\n"); main_menu(); break;
        }
    }
    else
    {
        puts("Error! Input a number.\n");
        __fpurge(stdin);
        main_menu();
    }
}
int main(void)
{
    typedef struct
    {
        char nome[30];
        float matematica, fisica, media;
    }Alunos;
 
    Alunos alunos[DIM];
    int count;
 
    for(count = 0 ; count < DIM ; count++)
    {
        fflush(stdin);
        __fpurge(stdin);
        printf("\nNome do aluno %d: ", count+1);
        gets(alunos[count].nome);//melhor usar gets quando for strings
 
        printf("Nota de matematica: ");
        scanf("%f", &alunos[count].matematica);
 
        printf("Nota de fisica: ");
        scanf("%f", &alunos[count].fisica);
 
        alunos[count].media = (alunos[count].matematica + alunos[count].fisica)/2;
    }
 
    printf("\nExibindo nomes e medias:\n");
 
    for(count = 0 ; count < DIM ; count++)
    {
        printf("nAluno %d\n", count+1);
        printf("Nome: %s\n",alunos[count].nome);
        printf("Media: %.2f\n", alunos[count].media);
    }
 
    return 0;
}