Example #1
0
static void emit_bar(int64_t start, int64_t width, uint64_t count,
                     uint64_t max_count, uint64_t tot_count, uint64_t run_count,
                     char *buf, int buf_len,
                     int plus_spaces, int equal_spaces, int space_spaces) {
    char bar_buf[25];
    char plus_buf[40];
    char equal_buf[40];
    char space_buf[40];

    size_t j = 0;

    if (count > 0) {
        uint64_t bar = (((sizeof(bar_buf) - 1) * count) / max_count);
        while (j < bar && j < sizeof(bar_buf) - 1) {
            bar_buf[j] = '*';
            j++;
        }
    }
    bar_buf[j] = '\0';

    fill_spaces(plus_buf, sizeof(plus_buf), plus_spaces);
    fill_spaces(equal_buf, sizeof(equal_buf), equal_spaces);
    fill_spaces(space_buf, sizeof(space_buf), space_spaces);

    snprintf(buf, buf_len - 1, "%s%"PRIu64"+%"PRIu64"%s=%"PRIu64" %s%.2f%% %s",
             plus_buf, start, width, equal_buf, count, space_buf,
             100.0 * ((float) (count + run_count) / (float) tot_count), bar_buf);
}
int main(int argc, char* argv[]){
  
  char sentence1[] = "Hello world blah blah.";
  reverse(sentence1);
  
  char sentence2[] = "Hello world blah blah.";
  fill_spaces(sentence2, 'a' );
  
  int a = 4;
  int b = 7;
  swap_no_temp(a,b);
  
  int result;
  
  result = multiply_without_mult(a,b);
  printf("Result of %d * %d is %d \n", a, b, result);
  
  palindrome("racecar");
  palindrome("hello");
  
  unique_char("google");
  unique_char("gole");
  
  
  return 0;
}
Example #3
0
void getopt_long_show_help(const char *usage_instructions, struct option_extended long_options[], const char *short_options)
{
	//find maximum length of long options
	int max_length = 0;
	int index = 0;
	while (true) {
		const char *name = long_options[index].option.name;
		if (name == 0) {
			break;
		}
		int length = strlen(name);

		const char *argument = long_options[index].argument;
		if (argument != NULL) {
			length += strlen(argument);
		}

		if (length > max_length) {
			max_length = length;
		}
		index++;
	}
	max_length += 8; //extra signs that are displayed after the long option in --help

	//display initial description
	index = 0;
	printf("%s\n", usage_instructions);
	while (true) {
		char option_print_full[MAX_NUM_CHARS] = {0};
		fill_spaces(option_print_full, MAX_NUM_CHARS, MAX_NUM_CHARS);
		char *option_print = option_print_full;

		if (long_options[index].option.name == 0) {
			break;
		}

		//display short option
		if (has_short_option(short_options, long_options[index].option)) {
			option_print += snprintf(option_print, MAX_NUM_CHARS, " -%c,", long_options[index].option.val);
		} else {
			option_print += snprintf(option_print, MAX_NUM_CHARS, "    ");
		}

		//display long option
		option_print += snprintf(option_print, MAX_NUM_CHARS, "--%s", long_options[index].option.name);

		//display argument
		switch (long_options[index].option.has_arg) {
			case required_argument:
				option_print += snprintf(option_print, MAX_NUM_CHARS, "=%s", long_options[index].argument);
			break;

			case optional_argument:
				option_print += snprintf(option_print, MAX_NUM_CHARS, "[=%s] ", long_options[index].argument);
			break;
		}
		*option_print = ' ';

		option_print = option_print_full + max_length;
		if (long_options[index].description != NULL) {
			snprintf(option_print, MAX_NUM_CHARS, " %s", long_options[index].description);
		} else {
			snprintf(option_print, MAX_NUM_CHARS, " Documentation missing.");
		}
		printf("%s\n", option_print_full);
		index++;
	}
}
Example #4
0
int main(){
	
 	FILE *arq;
   	char *result;
	int i,j;
	int size_key = 8;
	char msg[] = "Uma criança nasce sem qualquer conhecimento, sem qualquer consciência de seu próprio eu. E quando uma criança nasce, a primeira coisa da qual ela se torna consciente não é ela mesma; a primeira coisa da qual ela se torna consciente é o outro. Isso é natural, porque os olhos se abrem para fora, as mãos tocam os outros, os ouvidos escutam os outros, a língua saboreia a comida e o nariz cheira o exterior. Todos esses sentidos abrem-se para fora. O nascimento é isso. Nascimento significa vir a esse mundo: o mundo exterior. Assim, quando uma criança nasce, ela nasce nesse mundo. Ela abre os olhos e vê os outros. O outro significa o tu.  Ela primeiro se torna consciente da mãe. Então, pouco a pouco, ela se torna consciente de seu próprio corpo. Esse também é o 'outro', também pertence ao mundo. Ela está com fome e passa a sentir o corpo; quando sua necessidade é satisfeita, ela esquece o corpo. É dessa maneira que a criança cresce. Primeiro ela se torna consciente do você, do tu, do outro, e então, pouco a pouco, contrastando com você, com tu, ela se torna consciente de si mesma. Essa consciência é uma consciência refletida. Ela não está consciente de quem ela é. Ela está simplesmente consciente da mãe e do que ela pensa a seu respeito. Se a mãe sorri, se a mãe aprecia a criança, se diz 'você é bonita', se ela a abraça e a beija, a criança sente-se bem a respeito de si mesma. Assim, um ego começa a nascer. Através da apreciação, do amor, do cuidado, ela sente que é ela boa, ela sente que tem valor, ela sente que tem importância. Um centro está nascendo. Mas esse centro é um centro refletido. Ele não é o ser verdadeiro. A criança não sabe quem ela é; ela simplesmente sabe o que os outros pensa a seu respeito. E esse é o ego: o reflexo, aquilo que os outros pensam. Se ninguém pensa que ela tem alguma utilidade, se ninguém a aprecia, se ninguém lhe sorri, então, também, um ego nasce - um ego doente, triste, rejeitado, como uma ferida, sentindo-se inferior, sem valor. Isso também é ego. Isso também é um reflexo.";
	int msg_lenght = (int) strlen (msg);

	Key *key;
	Cypher *original;
	Cypher *encripted;
	Cypher *desencripted;
	Cypher *breaked;

	key = (Key *)calloc(1,sizeof(Key));
	key->msg = (char *)calloc(size_key,sizeof(char));
	key->index = (int *)calloc(size_key,sizeof(int));

	original = (Cypher *)calloc(1,sizeof(Cypher));
	original->msg = (char *)calloc(msg_lenght,sizeof(char));
	original->lenght = msg_lenght;

	encripted = (Cypher *)calloc(1,sizeof(Cypher));
	encripted->msg = (char *)calloc(msg_lenght,sizeof(char));	
	encripted->lenght = msg_lenght;

	desencripted = (Cypher *)calloc(1,sizeof(Cypher));
	desencripted->msg = (char *)calloc(msg_lenght,sizeof(char));	
	desencripted->lenght = msg_lenght;

	breaked = (Cypher *)calloc(1,sizeof(Cypher));
	breaked->msg = (char *)calloc(msg_lenght,sizeof(char));	
	breaked->lenght = msg_lenght;

	strcpy(original->msg, msg);

	arq = fopen("key.txt", "rt");
 	if(arq == NULL)
		printf("Erro, nao foi possivel abrir o arquivo\n");
	
	while (!feof(arq)){
		result = fgets(key->msg, 100, arq);  
		if (result)
			printf("key: %s", key->msg);
		i++;
	}

	
	key->lenght = (int) strlen(key->msg);

	//Pegando o vetor de index
	get_indexKey(key);
	
	//Tirando os espaços em branco
	remove_whitespaces(original);
	original->lenght = (int) strlen(original->msg);
	
	//Preenchendo os espaços restantes
	fill_spaces(original);
	original->lenght = (int) strlen(original->msg);
	//Cifrando o texto
	cipher(key, original, encripted);
	encripted->lenght = (int) strlen(encripted->msg);
	//Decifrando o texto
	decipher(key, encripted, desencripted);
	
	for(j = 0; j < size_key;j++){
		printf("%d", key->index[j]);
	}

	printf("\nNormal: %s\n", original->msg);
	printf("\n\n");
	printf("Ciphed: %s\n", encripted->msg);
	printf("\n\n");
	printf("Deciphed: %s\n", desencripted->msg);
	printf("\n\n");
	
/*
	int key_break_size = 0;
	for (int i = 1; i <= 8; i++){
		key_break_size = i;
		permutations(K_SIZE, text);
    	}*/	

	//cypher(key, original, encripted);
	free(key);
	free(original);	
	free(encripted);
	free(desencripted);

	return 0;

}