Example #1
0
///(TRHREAD_PADRE) /////////////////////////////////
int main(int argc, const char * argv[]) {
    int id_T[filasA];
    pthread_t *hilos;
    hilos = (pthread_t *)malloc(sizeof(pthread_t)*(numThreads));
    pthread_mutex_init(&lock, NULL);
    
    inputMatrixABC();
    printMatrixC(); //<------------------------------------------------------------------------------- DIAGONAL -1
    
    srand(time(NULL));  //<--------------------------------------------------------------------------- WARNING
    idDelElegido = rand()%filasA;
    
    for (auxAf = 0; auxAf < filasA; auxAf++) {
        
        id_T[auxAf] = auxAf;
        pthread_create(hilos+auxAf, NULL, mapear, id_T+auxAf);
    }
    
    //JOINs
    for (auxAf = 0; auxAf < filasA; auxAf++)
        pthread_join(hilos[auxAf], NULL);
    
    printMatrixC();
    return 0;
}
Example #2
0
void ex9(){
	system("clear");
	int m = 4, hor = 1, vert = 1, countH = 0, countV = 0;
	char a[m][m], s[m];
	for (int k = 0; k<m; k++){
		for (int j = 0; j<m; j++){
			printf("Digite o caracter [%d][%d]: ", k+1, j+1);
			scanf(" %c", &a[k][j]);
		}
	}
	system("clear");
	printMatrixC(m, m, a);
	printf("Digite a string que deseja procurar: ");
	scanf("%s", s);
	for (int k = 0; k<m; k++){
		for (int j = 0; j<m; j++){
			if (a[k][j] != s[j]) hor = 0;
			if (a[j][k] != s[j]) vert = 0;
		}
		if(hor) countH++;
		if(vert) countV++;
	}
	system("clear");
	printf("A string %s verticalmente.\n", countH != 0 ? "ocorre" : "nao ocorre");
	printf("A string %s horizontalmente.\n", countV != 0 ? "ocorre" : "nao ocorre");
}