int main(void) { int i, j, pid; int segmento1, segmento2, segmento3, *p; int **mat1, **mat2, **mat3; segmento1 = alocaMatriz(MAT_WIDTH, MAT_HEIGHT); segmento2 = alocaMatriz(MAT_WIDTH, MAT_HEIGHT); segmento3 = alocaMatriz(MAT_WIDTH, MAT_HEIGHT); mat1 = (int * *) shmat(segmento1, 0, 0); preencheMatriz(mat1, MAT_WIDTH, MAT_HEIGHT); mat2 = (int * *) shmat(segmento2, 0, 0); preencheMatriz(mat2, MAT_WIDTH, MAT_HEIGHT); mat3 = (int * *) shmat(segmento3, 0, 0); printf("Matriz 1: \n"); imprimeMatriz(mat1, MAT_WIDTH, MAT_HEIGHT); printf("\nMatriz 2: \n"); imprimeMatriz(mat2, MAT_WIDTH, MAT_HEIGHT); for(i = 0; i < MAT_HEIGHT; i++) { pid = fork(); if(pid == 0) { for(j = 0; j < MAT_WIDTH; j++) { mat3[i][j] = mat1[i][j] + mat2[i][j]; } exit(0); } waitpid(-1, NULL, 0); } printf("\nMatriz 3: \n"); imprimeMatriz(mat3, MAT_WIDTH, MAT_HEIGHT); shmdt(mat1); shmctl(segmento1, IPC_RMID, 0); shmdt(mat2); shmctl(segmento2, IPC_RMID, 0); shmdt(mat3); shmctl(segmento3, IPC_RMID, 0); return 0; }
int main () { int n = 3, m = 3; int matriz[n][m]; int *a, *b; /* Questao 3 */ printf("Questao 1\n"); misterio(5); printf("Questao 2\n"); preencheMatriz(n,m,matriz); ehNula(n,m,matriz); printf("Questao 3\n"); a = (int*) malloc(sizeof(int)); b = (int*) malloc(sizeof(int)); *a = 27; *b = 16; printf("Chamando funcao divisao(27,16,5) - saida: %d\n", divisao(a,b,5)); printf("a = %d\tb = %d\n", *a, *b); printf("Chamando funcao divisao(27,16,3) - saida: %d\n", divisao(a,b,3)); printf("a = %d\tb = %d\n", *a, *b); return 0; }
int main(int argc, char *argv[]){ if (argc == 3){ // Nome do arquivo (argv[0]) mais os dois parâmetros char entrada[40] = "entrada/"; char saida[40] = "saida/"; int k; // Instâncias de palavras char *palavra; palavra = (char *) malloc (MAXCHAR * sizeof(char)); int tamPalavra; Matriz estados; // Matriz n x 2, onde n é o tamanho da string e possui dois estados, o atual e o anterior. strcat(entrada,argv[1]); strcat(saida,argv[2]); FILE * inp = abreArquivoLeitura(entrada); FILE * out = abreArquivoEscrita(saida); fscanf(inp, "%d ", &k); // Lê as k instâncias de problemas for (int l=0; l<k; l++){ fscanf(inp,"%s\n",palavra); tamPalavra = strlen(palavra); criaMatriz(2,tamPalavra+1,&estados); preencheMatriz(0,&estados); // Preenche matriz toda com 0 fprintf(out,"%d\n",lcs(palavra, tamPalavra, &estados)); //imprimeMatriz(estados); destroiMatriz(&estados); } free(palavra); fechaArquivo(inp); fechaArquivo(out); } else{ printf("Número incorreto de parâmetros. Fazer seguir exemplo:\n\n\t./tp2 input.txt output.txt\n\n"); exit(0); } return 0; }