riquezeppelin's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
9 (0.02 per day)
Joined:
04-December 11
Profile Views:
506
Last Active:
User is offline Feb 25 2012 12:36 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   riquezeppelin has not set their status

Posts I've Made

  1. In Topic: My program stops working in the beginning

    Posted 5 Dec 2011

    When I run my program it doesn't show me any error messages. The problem is, when the program asks me to type p and q (line 80-81) it stops working. When I say stops working I mean that problem when windows show you an error message and closes the program suddenly.
    Ps.: Can I attach a file here? I want to attach the file I'm using to run the program.

    http://www.ime.usp.b...-imagens-sujas/
    I'm using the file kid.pgm as input. (I don't know if you mean it when you said input hahahah)
  2. In Topic: My program stops working in the beginning

    Posted 5 Dec 2011

    
    # include <stdio.h>
    # include <string.h>
    # include <stdlib.h>
    # define max_name 256
    # define max 500
    # define valormax 255
    int read_pgm(char fname[],int M[max][max],int *m,int *n,int *maxval){
    FILE * arq;
    int i,j,k,l,aux;
    char key [128];
    /* Abre o arquivo de leitura*/
    arq=fopen(fname,"r");
    if(arq==NULL){
      printf("Erro na abertura do arquivo %s\n",fname);
      return 0;
      }
    /* Le dados do cabeçalho*/
    aux=fscanf(arq,"%s", key);
    if(aux!=1){
      printf("Erro na leitura do arquivo %s\n",fname);
      fclose(arq);
      return 0;
      }
    if(strcmp(key,"P2")!=0){
      printf("Formato desconhecido\n");
      fclose(arq);
      return 0;
      }
    aux=fscanf(arq,"%d %d %d",m,n,maxval);
    if(aux!=3){
      printf("Formato incorreto\n");
      fclose(arq);
      return 0;
      }
    
    
    for(i=0;i<*n;i++){
      for(j=0;j<*m;j++)
        fscanf(arq,"%d",&M[i][j]);
    }
    fclose(arq);
    return 1;
    }
    int write_pgm(char fname[],int M[][max],int m,int n,int maxval){
    /* Escreve no arquivo de saída*/
    FILE * saida;
    int i,j;
    saida=fopen(fname,"r");
    fprintf(saida,"P2");
    fprintf(saida,"%d %d",m,n);
    fprintf(saida,"%d",maxval);
    for(i=0;i<n;i++){
      for(j=0;j<m;j++)
        fprintf(saida,"%d",M[i][j]);
    fclose(saida);
    }
    return 0;
    }
    int main(){
    FILE * arq;
    FILE *saida;
    char fname[max_name];
    char key [128];
    int m,n,maxval; /* Número de colunas, linhas e maior valor da matriz recebida*/
    static int a[max][max]; /*Usada para guarda a matriz recebida e calcular a Matriz mediana*/
    int aux[max]; /* Auxiliar no cálculo da mediana de cada elemento*/
    int aux2,b,c,x,x1,x2,y,i,j,p,q,min; /*Auxiliares para cálculos variados em todo o programa*/
    printf("Digite o nome do arquivo de entrada:\n");
    scanf("%s",fname);
    j=read_pgm(fname,a,&m,&n,&maxval);
    if(j==0)
      return 0;
      for(i=0;i<n;i++){
        for(j=0;j<m;j++)
        printf("%d",a[i][j]);
    }
    printf("\n");
    printf("%d %d",n,m);
    printf("\n");
    printf("Digite o tamanho da vizinhança (p q):");
    scanf("%d %d",&p,&q);
    x=p/2;
    y=q/2;
    /* Construção da matriz mediana*/
    /* Elementos da matriz original que serão utilizados*/
    for(i=0+x;i<n-x;i++){
      for(j=0+y;j<m-y;j++){
          /* "Pega" a vizinhança dos elementos */
        for(b=i-x;b<i+x;b++){
          for(c=j-y;c<j+y;c++)
            aux[b+c]=a[b][c];
        }
        /* Ordena o vetor para achar a mediana*/
        for(x1=0;x1<(p*q)-1;x1++){
          min=aux[x1];
          for(x2=(x1+1);x2<(p*q);x2++){
            if(aux[x2]<min)
              min=aux[x2];
            aux2=aux[x1];
            aux[x1]=aux[min];
            aux[min]=aux2;
            }
        }
        a[i][j]=aux[(p*q)/2];
      }
    }
    /* Colocando med=0 nos elementos com a vizinhança não definida*/
    
    for(i=0;i<x;i++){
      for(j=0;j<m;j++)
        a[i][j]=0;
    }
    for(i=n-x;i<n;i++){
        for(j=0;j<m;j++)
          a[i][j]=0;
    }
    for(j=0;j<y;j++){
      for(i=0;i<n;i++)
        a[i][j]=0;
    }
    for(j=m-y;j<m;j++){
      for(i=0;i<n;i++)
        a[i][j]=0;
    }
    if(m<16&&n<16){
      for(i=0;i<n;i++){
        for(j=0;j<m;j++)
          printf("%d",a[i][j]);
      }
    }
    printf("Digite o nome do arquivo de saida:");
    scanf("%s",fname);
    write_pgm(fname,a,m,n,maxval);
    return 0;
    }
    
    
  3. In Topic: My program stops working in the beginning

    Posted 5 Dec 2011

    No, my compiler didn't show me. What must I change in my compiler? And, I was able to change the warnings 3 and 6. Do you know what can I do to change the others?
    Ps.: Your last post was very very helpful but my program is still not working.
  4. In Topic: My program stops working in the beginning

    Posted 4 Dec 2011

    I'm sorry, I don't know if it will answer your question but I'm using codeblocks and "-Wall -ansi -pedantic -O2" that's "activated" in my Codeblocks. I hope I could answer you.
  5. In Topic: My program stops working in the beginning

    Posted 4 Dec 2011

    I don't have any warnings. I'm sorry but, can you explain what is wrong with the lines 129 and 39? I don't see what's wrong in this lines.

    Ps.: I configured my compiler to show warnings so, i don't think the program has warnings.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Comments

riquezeppelin has no profile comments yet. Why not say hello?