• Jueves 2 de Mayo de 2024, 05:33

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - amedinadiaz

Páginas: [1]
1
C/C++ / "paint" Para Ms-dos
« en: Viernes 23 de Abril de 2004, 03:15 »
Weno os lo dejo, aun no esta terminao hay algunos fallos aun pero la base si que funciona. Concretamente falla al borrar algun elemento de la imagen, y un par de cosillas mas, pero weno os lo pongo para el que le interese, cualkier opinion sera bien recibida y posibles mejoras o ayuda aun mas!

PD: Esta en ingles, xq yo studio en Inglaterra.

Código: Text
  1.  
  2. /*****************************************************/
  3. /* Author: Antonio Medina and Fawzan Ghulam          */
  4. /* Date: 10-2-04                                     */
  5. /* EE1E2 FINAL PROJECT                               */
  6. /* DRAWING PACKAGE                                   */
  7. /*****************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <malloc.h>
  12. #include <math.h>
  13. #define PI 3.14
  14.  
  15. struct drawing
  16. {
  17.   int width;
  18.   int height;
  19.   char** data;
  20. }A;
  21.  
  22. struct node
  23. {
  24.     char name[6];
  25.     int ID_no;
  26.     int x1;
  27.     int x2;
  28.     int y1;
  29.     int y2;
  30.     int centrex;
  31.     int centrey;
  32.     int radius;
  33.     struct node* next;
  34. };
  35. struct node* mknode(char name[6], int ID_no,int x1,int x2,int y1,int y2,int radius,int centrex,int centrey)
  36. {
  37.     struct node* np;
  38.  
  39.     np = (struct node*)malloc(sizeof(struct node));
  40.  
  41.     if (np)
  42.     {
  43.         strcpy(np->name,name);
  44.         np->ID_no=ID_no;
  45.         np->x1=x1;
  46.         np->x2=x2;
  47.         np->y1=y1;
  48.         np->y2=y2;
  49.         np->centrex=centrex;
  50.         np->centrey=centrey;
  51.         np->radius=radius;
  52.         np->next=NULL;
  53.     }
  54.  
  55.     return np;  
  56. }
  57.  
  58. struct node* append_node(struct node** head, struct node* np)
  59. {
  60.      struct node* n;
  61.  
  62.      if(*head==NULL)
  63.      *head=np;
  64.      else
  65.      {
  66.            for (n=*head; n->next!=NULL; n=n->next);
  67.            n->next=np;
  68.      }
  69.  
  70.  return np;
  71. }
  72.  
  73. void display_list(struct node* head)
  74. {
  75.      struct node* n;
  76.  
  77.      for (n=head; n!=NULL; n=n->next)
  78.      {
  79.           if (strcmp(n->name,"rect")==0)
  80.                 printf("%d: %s from %d %d to %d %d\n", n->ID_no, n->name, n->x1, n->y1, n->x2, n->y2);
  81.                
  82.           else if (strcmp(n->name,"circle")==0)
  83.                 printf("%d: %s, centre %d %d and radius %d\n", n->ID_no, n->name, n->centrex, n->centrey, n->radius);
  84.  
  85.           else if (strcmp(n->name,"line")==0)
  86.                 printf("%d: %s from %d %d to %d %d\n", n->ID_no, n->name, n->x1, n->y1, n->x2, n->y2);
  87.      }
  88. }
  89.  
  90. void commands (void)
  91. {
  92.  
  93.   printf("*********************\n");
  94.   printf("* POSSIBLE COMMANDS *\n");
  95.   printf("*********************\n");
  96.   printf(" -----------------------------------------------\n");
  97.   printf("|  - create (width) (height)                    |\n");
  98.   printf("|  - r                                          |\n");
  99.   printf("|  - clear                                      |\n");
  100.   printf("|  - invert                                     |\n");
  101.   printf("|  - line (from) (to)                           |\n");
  102.   printf("|  - rect (corner1, corner2) (corner3, corner4) |\n");
  103.   printf("|  - circle (centre) (radius)                   |\n");
  104.   printf("|  - fill (x) (y)                               |\n");
  105.   printf("|  - list                                       |\n");
  106.   printf("|  - delete (object_number)                     |\n");
  107.   printf("|  - exit                                       |\n");
  108.   printf(" -----------------------------------------------\n");
  109. }
  110.  
  111. void create(struct drawing *p1)
  112. {
  113.   int width, height;
  114.  
  115.   p1->data=(char**)(malloc(p1->width*sizeof(char*)));
  116.  
  117.   for(width=0; width<p1->width; width++)
  118.     p1->data[width]=(char*)(malloc(p1->height*sizeof(char)));
  119.  
  120.   for(width=0; width<p1->width; width++)
  121.     for(height=0; height<p1->height; height++)
  122.       p1->data[width][height]='.';
  123.  
  124. }
  125. void invert(struct drawing *p1)
  126. {
  127.   int width, height;
  128.  
  129.   for(width=0; width<p1->width; width++)
  130.     for(height=0; height<p1->height; height++)
  131.       if(p1->data[width][height]=='*')
  132.         p1->data[width][height]='.';
  133.       else if(p1->data[width][height]=='.')
  134.         p1->data[width][height]='*';
  135.  
  136. }
  137. void clear(struct drawing *p1)
  138. {
  139.   int width, height;
  140.  
  141.   for(width=0; width<p1->width; width++)
  142.     for(height=0; height<p1->height; height++)
  143.       p1->data[width][height]='.';
  144. }
  145.  
  146. void refresh(struct drawing *p1)
  147. {
  148.   int width, height;
  149.  
  150.   for(height=p1->height-1; height>=0; height--)
  151.   {
  152.     for(width=0; width<p1->width; width++)
  153.       printf("%c", p1->data[width][height]);
  154.       printf("\n");
  155.   }
  156. }
  157.  
  158. void line(struct drawing *p1, int x1, int x2, int y1, int y2, int del)
  159. {
  160.   int dx, dy, i,j;
  161.    
  162.                 if((x1<0)||(x2<0)||(y1<0)||(y2<0))
  163.                     printf("Error. You can't draw a negative line\n");
  164.                else if((x1>p1->width)||(x2>p1->width)||(y1>p1->height)||(y2>p1->height))
  165.                    printf("Error. Your line has excedeed the image limits\n");
  166.              else if ((y1<x1)||(y2<x2))
  167.                     printf("Error. You can't draw that shape.\n");
  168.      else
  169.      {
  170.     dx=x2-x1;
  171.     dy=y2-y1;
  172.  
  173.     if(dx>p1->width||dy>p1->height)
  174.       printf("Your dimensions are too large for the grid");
  175.     else
  176.     {
  177.  
  178.     if(dx>dy)
  179.     {
  180.       if(dx>0)
  181.       {
  182.         for(i=0; i<dx; i++)
  183.         {
  184.            j=(((i*dy)/dx)+0.5);
  185.            p1->data[x1+i][y1+j]='*';
  186.         }
  187.     }
  188.     else
  189.     {
  190.        for(i=0; i<dx; i--)
  191.        {
  192.          j=(((i*dy)/dx)+0.5);
  193.          p1->data[x1+i][y1+j]='*';
  194.        }
  195.     }
  196.        }
  197.        else
  198.        {
  199.       if(dy>0)
  200.       {
  201.         for(j=0; j<dy; j++)
  202.          {
  203.            i=(((j*dx)/dy)+0.5);
  204.            p1->data[x1+i][y1+j]='*';
  205.         }
  206.       }
  207.       else
  208.       {
  209.         for(j=0; j<dy; j--)
  210.          {
  211.           i=(((j*dx)/dy)+0.5);
  212.           p1->data[x1+i][y1+j]='*';
  213.         }
  214.       }
  215.     }
  216.     }
  217.  
  218.   }
  219. }
  220.  
  221. void circle(struct drawing *p1, int x1, int y1, int r, int del)
  222. {
  223.   int i, j;
  224.   float deg, theta;
  225.  
  226.  
  227.  
  228.   if((x1<0)||(y1<0))
  229.     printf("Error. You can't draw a negative circle\n");
  230.   else if((x1>p1->width)||(y1>p1->height))
  231.     printf("Error. Your circle has excedeed the image limits\n");
  232.  
  233.   else
  234.   {
  235.  
  236.     for(deg=0; deg<=360; deg=deg+5)
  237.     {
  238.       theta=((deg*PI)/180);
  239.    
  240.       i=x1+r*cos(theta)+0.5;
  241.       j=y1+r*sin(theta)+0.5;
  242.  
  243.       p1->data[i][j]='*';
  244.     }
  245.   }
  246. }
  247. void rect(struct drawing *p1, int x1, int x2, int y1, int y2, int del)
  248. {
  249.   int dx, dy, i;
  250.  
  251.  
  252.   if((x1<0)||(x2<0)||(y1<0)||(y2<0))
  253.     printf("Error. You can't draw a negative rectangle\n");
  254.   else if((x1>p1->width)||(x2>p1->width)||(y1>p1->height)||(y2>p1->height))
  255.     printf("Error. Your rect has excedeed the image limits\n");
  256.   else if ((y1<x1)||(y2<x2))
  257.     printf("Error. You can't draw that shape.\n");
  258.  
  259.   else
  260.   {
  261.  
  262.   dx=x2-x1;
  263.   dy=y2-y1;
  264.  
  265.   if(dx>p1->height||dy>p1->width)
  266.     printf("Your dimensions are too large for the grid");
  267.   else
  268.   {
  269.  
  270.   if((dy>0)&&(dx>0))
  271.   {
  272.  
  273.     for (i=0; i<dx; i++)
  274.       p1->data[x1+i][y1]='*';
  275.  
  276.         for (i=0; i<dy; i++)
  277.             p1->data[x1][y1+i]='*';
  278.  
  279.         for (i=dx;i>=0; i--)
  280.       p1->data[x2-i][y2]='*';
  281.  
  282.     for (i=dy;i>=0; i--)
  283.       p1->data[x2][y2-i]='*';
  284.  
  285.   }
  286.   else if((dy<0)&&(dx<0))  
  287.    {
  288.       for (i=dx; i<=0; i++)
  289.         p1->data[x1+i][y1]='*';
  290.  
  291.       for (i=dy; i<=0; i++)
  292.         p1->data[x1][y1+i]='*';
  293.  
  294.       for (i=dx;i<=0; i++)
  295.         p1->data[x2-i][y2]='*';
  296.  
  297.       for (i=dy;i<=0; i++)
  298.         p1->data[x2][y2-i]='*';
  299.  
  300.   }
  301.     else if(dy>0&&dx<0)
  302.     {
  303.  
  304.       for (i=dx; i<=0; i++)
  305.         p1->data[x1+i][y1]='*';
  306.  
  307.       for (i=0; i<dy; i++)
  308.         p1->data[x1][y1+i]='*';
  309.  
  310.       for (i=dx;i<=0; i++)
  311.         p1->data[x2-i][y2]='*';
  312.  
  313.       for (i=dy;i>=0; i--)
  314.         p1->data[x2][y2-i]='*';
  315.  
  316.     }
  317.     else if((dy<0)&&(dx>0))
  318.     {
  319.  
  320.       for (i=0; i<=dx; i++)
  321.         p1->data[x1+i][y1]='*';
  322.  
  323.       for (i=dy; i<=0; i++)
  324.         p1->data[x1][y1+i]='*';
  325.  
  326.       for (i=dx;i>=0; i--)
  327.         p1->data[x2-i][y2]='*';
  328.  
  329.       for (i=dy;i<=0; i++)
  330.         p1->data[x2][y2-i]='*';
  331.     }
  332.   }
  333. }
  334.  
  335. }
  336.  
  337. void fill(int x, int y, struct drawing *p1)
  338. {    
  339.  
  340.       p1->data[x][y]='*';
  341.  
  342.       if((x+1>=0)&&(x+1<p1->width))
  343.         if((y>=0)&&(y<p1->height))
  344.           if(p1->data[x+1][y]=='.')
  345.             fill(x+1,y, p1);
  346.  
  347.       if((x-1>=0)&&(x-1<p1->width))
  348.         if((y>=0)&&(y<p1->height))
  349.           if(p1->data[x-1][y]=='.')
  350.             fill(x-1,y, p1);
  351.  
  352.       if((x>=0)&&(x<p1->width))
  353.         if((y+1>=0)&&(y+1<p1->height))
  354.           if(p1->data[x][y+1]=='.')
  355.             fill(x,y+1, p1);
  356.  
  357.       if((x>=0)&&(x<p1->width))
  358.         if((y-1>=0)&&(y-1<p1->height))
  359.           if(p1->data[x][y-1]=='.')
  360.             fill(x,y-1, p1);
  361.  
  362.  
  363. }
  364. int delete_object(struct node** head, int ID_no, struct drawing *p1)
  365. {
  366.     struct node* n;
  367.     struct node* np;
  368.     int del=1;
  369.  
  370.      if (*head==NULL)
  371.            return 0;
  372.      else if (ID_no==(*head)->ID_no)
  373.      {
  374.            np=(*head);
  375.            if(strcmp(np->name,"circle")==0)
  376.                     circle(&A,np->centrex,np->centrey,np->radius,del);
  377.      }
  378.      if(strcmp(np->name,"line")==0)
  379.            line(&A,np->x1,np->y1,np->x2,np->y2,del);
  380.              
  381.      if(strcmp(np->name,"rect")==0)
  382.      {
  383.            rect(&A,np->x1,np->y1,np->x2,np->y2,del);
  384.  
  385.            *head=(*head)->next;
  386.            free(np);
  387.            return 1;
  388.      }
  389.      else
  390.      {
  391.            for(n=*head; (n->ID_no!=ID_no)&&(n->next!=NULL); n=n->next)
  392.                        np=n;
  393.  
  394.            if(n->ID_no==ID_no)
  395.            {
  396.                        if(strcmp(n->name,"circle")==0){
  397.                                  circle(&A,n->centrex,n->centrey,n->radius,del);
  398.            }
  399.            else if(strcmp(n->name,"line")==0)
  400.            {
  401.                        line(&A,n->x1,n->y1,n->x2,n->y2,del);
  402.            }
  403.            else if(strcmp(n->name,"rect")==0)
  404.            {
  405.               rect(&A, n->x1, n->y1,n->x2,n->y2,del);
  406.            }
  407.             np->next=n->next;
  408.             free(n);
  409.             return 1;
  410.       }
  411.  else
  412.  return 0;
  413.  }
  414. }
  415.  
  416. int main (void)
  417. {
  418.   char a[6];
  419.   struct drawing A;
  420.   struct node *n;
  421.   struct node *head=NULL;
  422.   int flag=0, i ,j, k=1, x1=0, x2=0, y1=0, y2=0, r, x=0, y=0, del=0, ID_no=0;
  423.  
  424.   printf("DRAWING PACKAGE FOR MS-DOS 1.0\n");
  425.   printf("------------------------------\n");
  426.   printf("\n");
  427.   commands();
  428.  
  429.   printf("Enter your command:\n");
  430.  
  431.   while(strcmp(a, "exit")!=0)
  432.   {
  433.     scanf("%s", a);
  434.  
  435.     if(strcmp(a, "create")==0)
  436.     {
  437.       if(flag==1)
  438.         printf("Error. You can't create more than one image per session.\n");
  439.    
  440.       else
  441.       {
  442.         printf("Enter width:");
  443.         scanf("%d", &A.width);
  444.         printf("Enter height:");
  445.         scanf("%d", &A.height);
  446.         create(&A);
  447.         flag++;
  448.       }
  449.     }
  450.     else if(strcmp(a, "r")==0)
  451.       refresh(&A);
  452.     else if(strcmp(a, "invert")==0)
  453.       invert(&A);
  454.     else if(strcmp(a, "exit")==0)
  455.     {
  456.       printf("\n");
  457.       printf("Thanks for using this program\n");
  458.       printf("-----------------------------\n");
  459.       return 0;
  460.     }
  461.     else if(strcmp(a, "clear")==0)
  462.       clear(&A);
  463.      
  464.     else if(strcmp(a, "fill")==0)
  465.     {
  466.       printf("Enter starting point:");
  467.       scanf("%d %d", &i, &j);
  468.       fill(i, j, &A);
  469.     }
  470.     else if(strcmp(a, "list")==0)
  471.             display_list(head);
  472.        
  473.         else if(strcmp(a, "delete")==0)
  474.         {
  475.             printf("Enter ID:");
  476.             scanf("%d", &ID_no);
  477.  
  478.             if(delete_object(&head,ID_no,&A))
  479.                         printf("Object no.%d successfully deleted\n", ID_no);
  480.  
  481.         }    
  482.     else if((strcmp(a, "line"))||(strcmp(a, "circle"))||(strcmp(a, "rect"))==0)
  483.     {
  484.         if(strcmp(a, "line")==0)
  485.         {
  486.             printf("Insert point 1\n");
  487.             scanf("%d %d", &x1,&y1);
  488.             printf("Insert point 2\n");
  489.                 scanf("%d %d", &x2,&y2);
  490.                 line(&A, x1, x2, y1, y2, del);
  491.             }
  492.       else if(strcmp(a, "circle")==0)
  493.       {
  494.                printf("Enter Coordinates:");
  495.                scanf("%d %d", &x1, &y1);
  496.                printf("Enter Radius:");
  497.                scanf("%d", &r);
  498.           circle(&A, x1, y1, r, del);
  499.           }
  500.             else if(strcmp(a, "rect")==0)
  501.             {
  502.            printf("Enter x1, y1:");
  503.          scanf("%d %d", &x1, &y1);
  504.          printf("Enter x2, y2:");
  505.          scanf("%d %d", &x2, &y2);
  506.                 rect(&A, x1, x2, y1, y2, del);
  507.             }
  508.            
  509.             n=mknode(a, k, x1, x2, y1, y2, r, x, y);
  510.             append_node(&head, n);
  511.             k++;
  512.     }
  513.     else
  514.       printf("Error. That is not a possible command.\n");
  515.  
  516.   }
  517.  
  518.   return 0;
  519. }
  520.  

2
C/C++ / Re: Estructuras De Datos Dinamicos
« en: Viernes 23 de Abril de 2004, 01:05 »
Pues si, era eso :P  si es que al final siempre me pasa lo mismo!! Lo mas tonto...

Gracias a los 2 :hola:

3
C/C++ / Estructuras De Datos Dinamicos
« en: Jueves 22 de Abril de 2004, 22:06 »
Estoy experimentando un poco con colas, y etc. y al crear este programa (que deberia estar bien segun mi parecer y mostrar los numeros del 1 al 10) el compilador (Dev) me dice que "two or more data types in mknode"  :blink: Y no tngo ni idea que hacer. Si alguien puede decirme que es lo que esta mal o que falta se lo agradeceria.

Código: Text
  1.  
  2. #include <stdio.h>
  3.  
  4. struct node
  5. {
  6.     int ID_no;
  7.     struct node* next;
  8. }
  9. struct node* mknode(int ID_no)
  10. {
  11.     struct node* np;
  12.  
  13.     np = (struct node*)malloc(sizeof(struct node));
  14.  
  15.     if (np)
  16.     {
  17.         np->ID_no=ID_no;
  18.         np->next=NULL;
  19.     }
  20.  
  21.     return np;  
  22. }
  23.  
  24. struct node* append_node(struct node** head, struct node* np)
  25. {
  26.      struct node* n;
  27.  
  28.      if(*head==NULL)
  29.      *head=np;
  30.      else
  31.      {
  32.            for (n=*head; n->next!=NULL; n=n->next);
  33.            n->next=np;
  34.      }
  35.  
  36.  return np;
  37. }
  38.  
  39. void display_list(struct node* head)
  40. {
  41.      struct node* n;
  42.  
  43.      for (n=head; n!=NULL; n=n->next)
  44.           printf("Dato numero= %d\n", n->ID_no);
  45.  
  46. }
  47. int main(void)
  48. {
  49.     int i;
  50.     struct node*n;
  51.     struct node* head=NULL;
  52.    
  53.     for(i=0; i<10; i++)
  54.     {
  55.         n=mknode(i);
  56.        
  57.         append_node(&head, n);
  58.        
  59.     }
  60.    
  61.     display_list(head);
  62.    
  63.     return 0;
  64.    
  65. }
  66.  
  67.  

4
C/C++ / Re: Presione Cualquier Tecla Para Continuar....
« en: Jueves 25 de Marzo de 2004, 20:44 »
Para limpiar la pantalla ya descubri un modo que no da warnings ni errores que creo se ha dicho aqui de forma parecida pero no exacta:

#include <stdlib.h>
.
.
.
system("cls");

Creo que lo que no se habia mencionado era el uso de la libreria <stdlib.h> ya que si no al compilar te da un "warning". Asi queda perfecto.

5
C/C++ / Re: Problema Con <graphics.h> Y Algunas Funciones
« en: Jueves 25 de Marzo de 2004, 20:43 »
para limpiar la pantalla ya descubri un modo que no da warnings ni errores que creo se ha dicho aqui de forma parecida pero no exacta:

#include <stdlib.h>
.
.
.
system("cls");

Creo que lo que no se habia mencionado era el uso de la libreria <stdlib.h> ya que si no al compilar te da un "warning".

Si alguien sabe sobre textcolor, etc, y porque la libreria graphics.h no me la acepta el Visual C++ que lo diga plis.

6
C/C++ / Re: Como Salgo De Un Programa?
« en: Jueves 25 de Marzo de 2004, 18:52 »
joer mas facil imposible:


...
return 0;
}

si es una funcion que retorne valor, si no, simplmente llama la funcion en tu main(void) y despues pon ese return 0; y listos.

7
C/C++ / Problema Con <graphics.h> Y Algunas Funciones
« en: Jueves 25 de Marzo de 2004, 18:41 »
Pues estaba terminando de leer el tutorial de C que teneis y al incluir <graphics.h>, me da un error el compilador (Visual C++). Tambien quiero intentar usar algunas de las funciones de <conio.h> como clrscr(); pero tambien el programa me da error (las inclui dentro de int main (void))

Si alguien me puede ayudar seria d agradecer.

8
C/C++ / Re: Correcion De Palabras De Un Texto
« en: Martes 2 de Marzo de 2004, 19:05 »
Y sigo respondiendome a mi mismo. Para imprimir el numero d linea de la palabra erronea tan solo hay que anadir al "printf("%s\n", word);" un %d y , count2.

Seguire informando para el que le interese:P

9
C/C++ / Re: Correcion De Palabras De Un Texto
« en: Martes 2 de Marzo de 2004, 18:48 »
Perdonen x ser un pokito tontito, ya descubri el error simplemente tenia que inicializar i=0 en el loop FOR:P A veces lo mas sencillo es lo mas jodido de ver!!

De todas formas os dejo aki el programa a ver si a alguno le interesa desarrollarlo. El objetivo es que imprima la palabra erronea, con la linea de texto en la que esta y si encuentra una palabra similar en el diccionario a la erronea, imprimirla tambien. Si la palabra erronea aparece mas de 3 veces, debe guardarla en un archivo nuevo.

Eso es todo, me pondre a ello en seguida!

10
C/C++ / Correcion De Palabras De Un Texto
« en: Martes 2 de Marzo de 2004, 18:37 »
Bueno pues tengo el siguiente programa que deberia imprimir en pantalla las palabras mal escritas de un texto (a partir de un diccionario que os incluyo, al igual que el texto), y con este codigo lo hace de hecho. El problema es que ademas de las palabras mal escritas imprime una serie de letras que no deberia imprimir, aqui os dejo el output del programa:

Citar
skeptics
balloons
a
skeptics
a
studise
snorg
e
g
sagan
mya
planest
lief
civilization
resolution
sucy
a
a
civilization
a
histoyy
a
civilization
postulate
a
wide
civilization
a
mj
mj
u
s
a
mj
majestic
thees
a
a
a
a
skeptic
Press any key to continue

Que imprima e y g es normal porque estas palabras no estan en el diccionario, pero que imprima la "a" si que no lo entiendo. Por favor, a ver si alguien entiende cual es el problema y puede ayudarme. Gracias. Aqui os dejo el codigo que he hecho:


Código: Text
  1.  
  2. #include &#60;stdio.h&#62;
  3. #include &#60;string.h&#62;
  4. #include &#60;malloc.h&#62;
  5.  
  6. int main (void)
  7. {
  8.   FILE *text_file, *dict;
  9.   char buffer[1][500];
  10.   char buf2[300];
  11.   char **pdict;
  12.   char *word, *pch;
  13.   int count=0, count2=0, flag=0;
  14.   int i, scan, length, x;
  15.  
  16.   dict=fopen(&#34;dict.txt&#34;, &#34;r&#34;);
  17.   
  18.   if(dict==NULL)
  19.     printf(&#34;Dictionary failed.&#092;n&#34;);
  20.   else
  21.   {
  22.     while((fgets(buffer,500, dict))!=NULL)
  23.     {
  24.       count++;
  25.     }
  26.   }
  27.   fclose(dict);
  28.   pdict=(char**)(malloc(count*sizeof(char*)));
  29.  
  30.   dict=fopen(&#34;dict.txt&#34;, &#34;r&#34;);
  31.   if(dict==NULL)
  32.     printf(&#34;Dictionary failed.&#092;n&#34;);
  33.  
  34.   for(x=0; x&#60;count; x++)
  35.   {
  36.     scan=fscanf(dict, &#34;%s&#34;, buffer[0]);
  37.  
  38.     length=strlen(buffer[0]);
  39.     pdict[x]=(char*)(malloc(length*sizeof(char)));
  40.     strcpy(pdict[x], buffer[0]);
  41.   }
  42.  
  43.   text_file=fopen(&#34;textfile.txt&#34;, &#34;r&#34;);
  44.  
  45.   if(text_file==NULL)
  46.     printf(&#34;Text File failed.&#092;n&#34;);
  47.   else
  48.   {
  49.     while((fgets(buf2,300,text_file))!=NULL)
  50.     {
  51.       count2++;
  52.       pch=strtok(buf2,&#34; )(&#092;n*?-%+.,!:1234567890&#092;&#092;&#092;&#34;&#34;);
  53.       while(pch!=NULL)
  54.       {
  55.         flag=0;
  56.         word=_strlwr(pch);
  57.         for(i=1;i&#60;count;i++)
  58.         {
  59.           if(strcmp(pdict[i],word)==0)
  60.           {
  61.             flag=1;
  62.             break;
  63.           }
  64.         }
  65.         if(flag==0)
  66.         {
  67.           printf(&#34;%s&#092;n&#34;,word);
  68.         }
  69.         pch=strtok(NULL,&#34; -&#092;n)(*?%!+.,1:234567890&#092;&#092;&#092;&#34;&#34;);
  70.  
  71.       }
  72.  
  73.     }
  74.   }
  75.   fclose(text_file);
  76.         
  77.   return 0;
  78. }
  79.  
  80.  

Como siempre si descubro como hacerlo ya os lo dire por aqui. Cualquier correcion, aunque sea secundaria es bienvenida.

EL DICCIONARIO Y EL ARCHIVO DE TEXTO ESTAN EN ESTE ZIP.

11
C/C++ / Re: Imprimir En Tu Prog. El Contenido De Un Fichero
« en: Viernes 27 de Febrero de 2004, 16:17 »
Gracias x la ayuda, al final encontre una manera de hacerlo que se ajustaba a lo que me pedian y que os dejo aqui (seguramente hay formas mas faciles y rapidas pero no podia usarlas):

Código: Text
  1.  
  2. **************************************************************/
  3. /* Authors: Antonio Medina, Paul Griffiths and Clarisse Smith */
  4. /* Date: 24-2-04                                              */
  5. /* EE1K2: STRUCTURED SOFTWARE DESIGN                          */
  6. /* ESA GROUP                                                  */
  7. /* GROUP ORANGE - OBJECT MANAGER MODULE                       */
  8. /**************************************************************/
  9.  
  10. #include &#60;stdio.h&#62;
  11. #include &#60;stdlib.h&#62; //Including this library in order to use the 'malloc' function.
  12. #include &#60;string.h&#62; //Including this library in order to use the 'strcpy' and the
  13.         //'strlen' functions.
  14.  
  15. struct object2 //Creating a structure which contains all the info about the object in the map.
  16. {
  17.     int* objtype;
  18.     int* objid;
  19.     int* gridx;
  20.     int* gridy;
  21.     int* moveable;
  22.     int* passable;
  23.     int* live;
  24.     int* health;
  25. };
  26.  
  27. struct object //Creating another structure to store the object type, name and description.
  28. {
  29.     int* objtype;
  30.     char** objname;
  31.     char** objdesc;
  32. };
  33.  
  34. void object_type_name_description(struct object *p1) //Creating a function to print the object
  35. {              //type, name and description.
  36.     FILE *obj_name_desc; //Declaring the file
  37.     char buffer[3][100]; //This buffer will store all the temporary data.
  38.     int i, scan, length;
  39.  
  40.     obj_name_desc=fopen(&#34;objname.txt&#34;,&#34;r&#34;); //Opening the file
  41.  
  42.     //Allocating memory for the object type, name and description.
  43.     p1-&#62;objtype=(int*)(malloc(17*sizeof(int)));
  44.     p1-&#62;objname=(char**)(malloc(17*sizeof(char*)));
  45.     p1-&#62;objdesc=(char**)(malloc(17*sizeof(char*)));
  46.  
  47.     for(i=0; (i&#60;17)||(scan==EOF); i++)
  48.     {
  49.   scan=fscanf(obj_name_desc,&#34;%s %s %s&#34;, buffer[0], buffer[1], buffer[2]); //Scaning from
  50.                         //the file.
  51.   p1-&#62;objtype[i]=atoi(buffer[0]); //Converting strings into integers.
  52.  
  53.   length=strlen(buffer[1]);
  54.   p1-&#62;objname[i]=(char*)(malloc(length*sizeof(char)));
  55.   strcpy(p1-&#62;objname[i], buffer[1]); //Copying from buffer to objname.
  56.  
  57.   length=strlen(buffer[2]);
  58.   p1-&#62;objdesc[i]=(char*)(malloc(length*sizeof(char)));
  59.   strcpy(p1-&#62;objdesc[i], buffer[2]); //Copying from buffer to objname.
  60.  
  61.  
  62.     }
  63.     for(i=0; i&#60;17; i++)
  64.     printf(&#34;%d %s %s&#092;n&#34;, p1-&#62;objtype[i], p1-&#62;objname[i], p1-&#62;objdesc[i]);
  65.  
  66. }
  67. void object_id (struct object2 *p2) //Creating another function to show type, id, gridx, gridy,
  68. {           //moveable, passable, live and health.
  69.     int i, scan;
  70.     char buffer2[7][10];
  71.     FILE *object_id;
  72.  
  73.     object_id=fopen(&#34;objstruct.txt&#34;, &#34;r&#34;);
  74.  
  75.     //Allocating memory.
  76.     p2-&#62;objtype=(int*)(malloc(64*sizeof(int)));
  77.     p2-&#62;objid=(int*)(malloc(64*sizeof(int)));
  78.     p2-&#62;gridx=(int*)(malloc(64*sizeof(int)));
  79.     p2-&#62;gridy=(int*)(malloc(64*sizeof(int)));
  80.     p2-&#62;moveable=(int*)(malloc(64*sizeof(int)));
  81.     p2-&#62;passable=(int*)(malloc(64*sizeof(int)));
  82.     p2-&#62;live=(int*)(malloc(64*sizeof(int)));
  83.     p2-&#62;health=(int*)(malloc(64*sizeof(int)));
  84.  
  85.     for(i=0; ((i&#60;139)||(scan==EOF)); i++)
  86.     {
  87.   scan=fscanf(object_id, &#34;%s %s %s %s %s %s %s %s&#34;, buffer2[0], buffer2[1],
  88.     buffer2[2], buffer2[3], buffer2[4], buffer2[5], buffer2[6], buffer2[7]);
  89.  
  90.   //Converting strings into integers.
  91.   p2-&#62;objtype[i]=atoi(buffer2[0]);
  92.   p2-&#62;objid[i]=atoi(buffer2[1]);
  93.   p2-&#62;gridx[i]=atoi(buffer2[2]);
  94.   p2-&#62;gridy[i]=atoi(buffer2[3]);
  95.   p2-&#62;moveable[i]=atoi(buffer2[4]);
  96.   p2-&#62;passable[i]=atoi(buffer2[5]);
  97.   p2-&#62;live[i]=atoi(buffer2[6]);
  98.   p2-&#62;health[i]=atoi(buffer2[7]);
  99.  
  100.   printf(&#34;%d %d %d %d %d %d %d %d&#092;n&#34;, p2-&#62;objtype[i], p2-&#62;objid[i], p2-&#62;gridx[i],
  101.     p2-&#62;gridy[i], p2-&#62;moveable[i], p2-&#62;passable[i], p2-&#62;live[i], p2-&#62;health[i]);
  102.     }
  103. }  
  104.  
  105.  
  106. int main (void)
  107. {
  108.     struct object A;
  109.     struct object2 B;
  110.  
  111.    
  112.     object_type_name_description(&A);
  113.     printf(&#34;&#092;n&#34;);
  114.     object_id(&B);
  115.    
  116.  
  117.     return 0;
  118. }
  119.  
  120.  

Salu2!!

12
C/C++ / Imprimir En Tu Prog. El Contenido De Un Fichero
« en: Miércoles 25 de Febrero de 2004, 17:49 »
Alguno podria decirme como imprimir el conteido de un fichero (FILE *loquesea) en la pantalla de tu programa??

Por ejemplo, si tuviera escrito en un txt una algo asi:

1
2
3
4
5
6
7
8
9
10

Como ariais para que saliesen el contenido de este txt en vuestra pantalla? (sin crear otro fichero)

Y aun mas dificil (al menos para mi:P ejeje) como ariais para imprimir una serie de caracteres? Por ejemplo.

Hola me llamo Pedro.
Esto es una tonteria.
Tengo que esxcrbir algo.

Gracias x vuestro tiempo y si lo descubro ya lo pondre aqui!

13
C/C++ / Calculadora De Matrices Usando Estructuras
« en: Miércoles 18 de Febrero de 2004, 10:41 »
Al final pude lograr sacar la forma de hacer la multiplicacion de matrices (ejem, gracias x nada:P) y aki os dejo el programa completo, una calculadora de matrices, para al que le pueda servir de ayuda:

/*********************************************/
/* Author: Antonio Medina and Fawzan Ghulam           */
/* Date: 8-2-04                                                        */
/* EE1E2 LAB 4                                                         */
/* MATRIX CALC PROGRAM                                       */
/*********************************************/

#include <stdio.h>
#include <stdlib.h>

struct matrix
{
   int row;
   int col;
   float** data;
};
void allocate(struct matrix *p1)
{
   int row, col;

   p1->data=(float**)(malloc(p1->row*sizeof(float*)));

   for (row=0; row<p1->row; row++)
      p1->data[row]=(float*)(malloc(p1->col*sizeof(float)));

   printf("Enter matrix data:\n");
      for(row=0; row<p1->row; row++)
         for(col=0; col<p1->col; col++)
            scanf("%f", &p1->data[row][col]);

   for(row=0; row<p1->row; row++)
   {
      for(col=0; col<p1->col; col++)
         printf("%.2f ", p1->data[row][col]);
         printf("\n");
   }

}
void de_allocate(struct matrix *p1)
{
   int row;

   for(row=0; row<p1->row; row++)
         free(p1->data[row]);

   free(p1->data);
   
}
void add_matrix(struct matrix* pA, struct matrix* pB)
{
   int row, col;   

   if((pA->row==pB->row)&&(pA->col==pB->col))
   {

   
      for(row=0; row<pA->row; row++)
      {
         for(col=0; col<pA->col; col++)
            printf(" %.2f", pA->data[row][col]+ pB->data[row][col]);
            printf("\n");
      }
   }
   else
      printf("Error. Matrices must have the same number of rows and cols.\n");
   


}
void sub_matrix(struct matrix* pA, struct matrix* pB)
{
   int row, col;   

   
   if((pA->row==pB->row)&&(pA->col==pB->col))
   {

   
      for(row=0; row<pA->row; row++)
      {
         for(col=0; col<pA->col; col++)
            printf(" %.2f", pA->data[row][col]- pB->data[row][col]);
            printf("\n");
      }
   }
   else
      printf("Error. Matrices must have the same number of rows and cols.\n");
   


}

void multp_matrix(struct matrix* pA, struct matrix* pB)
{
   int i,j,k;
    float C=0.0;

   
    if(pA->col==pB->row)
   {
      for(i=0; i<pA->row; i++)
      {
         for(j=0; j<pA->row; j++)
         {
            C=0;
            
            for(k=0; k<pA->col; k++)
            {   
               C+=pA->data[k]*pB->data[k][j];
            }
            printf(" %.2f", C);
         }
         printf("\n");
   
      }

   }
   else
      printf("The number of cols in A has to be equal to the number of rows in B\n");
}

int main(void)
{
   struct matrix A,B;
   int menu=0;
   int flag=0;
   
   printf("Matrix Calculator 1.0\n");
   printf("---------------------\n");
   printf("\n");
   printf("1 - Enter matrices A & B\n");
   printf("2 - Add matrices\n");
   printf("3 - Subtract matrices\n");
   printf("4 - Multiply matrices\n");
   printf("5 - Quit program\n");

   while(menu!=5)
   {
      printf("\n");
      printf("Option:");
      scanf("%d", &menu);
      printf("\n");   
      switch(menu)
      {
         case 1:
            if(flag==1)
            {
                  de_allocate(&A);
                  de_allocate(&B);
            }
               printf("Number of rows in A:");
               scanf("%d", &A.row);
               printf("Number of columns in A:");
               scanf("%d", &A.col);
               allocate(&A);

               printf("\n");
               printf("Number of rows in B:");
               scanf("%d", &B.row);
               printf("Number of columns in B:");
               scanf("%d", &B.col);
               allocate(&B);

               flag=1;
           
               printf("\n");
               printf("1 - Enter matrices A & B\n");
               printf("2 - Add matrices\n");
               printf("3 - Subtract matrices\n");
               printf("4 - Multiply matrices\n");
               printf("5 - Quit program\n");

         break;
         case 2:
            printf("A + B=\n");

            add_matrix(&A, &B);

            break;
         case 3:
            printf("A - B=\n");

            sub_matrix(&A, &B);

            break;
         case 4:
            printf("A * B=\n");

            multp_matrix(&A, &B);

            break;
         case 5:
            return 0;
            break;
         default:
            printf("Not a valid input. Try again.\n");
            break;
      }

   }
      return 0;
}

14
C/C++ / Multiplicacion De Matrices Usando Punt. A Estruct.
« en: Miércoles 11 de Febrero de 2004, 14:44 »
Tengo el siguiente programa que os dejo (esta en ingles):

#include <stdio.h>
#include <stdlib.h>

struct matrix
{
int row;
int col;
float** data;
};

void allocate(struct matrix *p1)
{
int row, col;

p1->data=(float**)(malloc(p1->row*sizeof(float*)));

for (row=0; row<p1->row; row++)
p1->data[row]=(float*)(malloc(p1->col*sizeof(float)));

printf("Enter matrix data:\n");
for(row=0; row<p1->row; row++)
for(col=0; col<p1->col; col++)
scanf("%f", &p1->data[row][col]);

for(row=0; row<p1->row; row++)
{
for(col=0; col<p1->col; col++)
printf("%.2f ", p1->data[row][col]);
printf("\n");
}

}
void de_allocate(struct matrix *p1)
{
// int row, col;

// for(row=0; row<p1->row; row++)
// for(col=0; col<p1->col; col++)
// free(p1->data[row][col]);

free(p1->data);
}
void add_matrix(struct matrix* pA, struct matrix* pB)
{
int row, col;

if((pA->row==pB->row)&&(pA->col==pB->col))
{


for(row=0; row<pA->row; row++)
{
for(col=0; col<pA->col; col++)
printf(" %.2f", pA->data[row][col]+ pB->data[row][col]);
printf("\n");
}
}
else
printf("Error. Matrices must have the same number of rows and cols.\n");



}
void sub_matrix(struct matrix* pA, struct matrix* pB)
{
int row, col;


if((pA->row==pB->row)&&(pA->col==pB->col))
{


for(row=0; row<pA->row; row++)
{
for(col=0; col<pA->col; col++)
printf(" %.2f", pA->data[row][col]- pB->data[row][col]);
printf("\n");
}
}
else
printf("Error. Matrices must have the same number of rows and cols.\n");



}

int main(void)
{
struct matrix A,B;
int menu=0;

printf("Matrix Calculator 1.0\n");
printf("---------------------\n");
printf("\n");
printf("1 - Enter matrices A & B\n");
printf("2 - Add matrices\n");
printf("3 - Subtract matrices\n");
printf("4 - Multiply matrices\n");
printf("5 - Quit program\n");

while(menu!=5)
{
printf("\n");
printf("Option:");
scanf("%d", &menu);
printf("\n");
switch(menu)
{
case 1:
// free(&A);
printf("Number of rows in A:");
scanf("%d", &A.row);
printf("Number of columns in A:");
scanf("%d", &A.col);
allocate(&A);

printf("\n");
printf("Number of rows in B:");
scanf("%d", &B.row);
printf("Number of columns in B:");
scanf("%d", &B.col);
allocate(&B);

break;
case 2:
printf("A + B=\n");

add_matrix(&A, &B);

break;
case 3:
printf("A - B=\n");

sub_matrix(&A, &B);

break;
case 4:
printf("ddd\n");
break;
case 5:
return 0;
break;
default:
printf("Not a valid input. Try again.\n");
break;
}

}
return 0;
}

Se trata de una calculadora de matrices que suma, resta y multiplica. Tengo hechos todos los casos menos el de multiplicar, que no tengo ni idea de como hacerlo. Alguno podria echarme una ayudita?? En los requisitios me dice que tiene que ser una funcion que use punteros a estructuras o estructuras como en el caso de la suma y la resta. POR FAVOR ES MUY IMPORTANTE Y URGENTE, me juego mucha nota. Estaria eternamente agradecido de cualquier ayuda.

Antonio

15
C/C++ / Multiplicacion De Matrices Usando Punt. A Estruct.
« en: Miércoles 11 de Febrero de 2004, 14:42 »
Tengo el siguiente programa que os dejo (esta en ingles):

#include <stdio.h>
#include <stdlib.h>

struct matrix
{
   int row;
   int col;
   float** data;
};

void allocate(struct matrix *p1)
{
   int row, col;

   p1->data=(float**)(malloc(p1->row*sizeof(float*)));

   for (row=0; row<p1->row; row++)
      p1->data[row]=(float*)(malloc(p1->col*sizeof(float)));

   printf("Enter matrix data:\n");
      for(row=0; row<p1->row; row++)
         for(col=0; col<p1->col; col++)
            scanf("%f", &p1->data[row][col]);

   for(row=0; row<p1->row; row++)
   {
      for(col=0; col<p1->col; col++)
         printf("%.2f ", p1->data[row][col]);
         printf("\n");
   }

}
//void de_allocate(struct matrix *p1)
//{
//   int row, col;

//   for(row=0; row<p1->row; row++)
//      for(col=0; col<p1->col; col++)
//         free(p1->data[row][col]);

//   free(p1->data);
}
void add_matrix(struct matrix* pA, struct matrix* pB)
{
   int row, col;   

   if((pA->row==pB->row)&&(pA->col==pB->col))
   {

   
      for(row=0; row<pA->row; row++)
      {
         for(col=0; col<pA->col; col++)
            printf("         %.2f", pA->data[row][col]+ pB->data[row][col]);
            printf("\n");
      }
   }
   else
      printf("Error. Matrices must have the same number of rows and cols.\n");
   


}
void sub_matrix(struct matrix* pA, struct matrix* pB)
{
   int row, col;   

   
   if((pA->row==pB->row)&&(pA->col==pB->col))
   {

   
      for(row=0; row<pA->row; row++)
      {
         for(col=0; col<pA->col; col++)
            printf("         %.2f", pA->data[row][col]- pB->data[row][col]);
            printf("\n");
      }
   }
   else
      printf("Error. Matrices must have the same number of rows and cols.\n");
   


}

int main(void)
{
   struct matrix A,B;
   int menu=0;
   
   printf("Matrix Calculator 1.0\n");
   printf("---------------------\n");
   printf("\n");
   printf("1 - Enter matrices A & B\n");
   printf("2 - Add matrices\n");
   printf("3 - Subtract matrices\n");
   printf("4 - Multiply matrices\n");
   printf("5 - Quit program\n");

   while(menu!=5)
   {
      printf("\n");
      printf("Option:");
      scanf("%d", &menu);
      printf("\n");   
      switch(menu)
      {
         case 1:
       //   free(&A);
            printf("Number of rows in A:");
            scanf("%d", &A.row);
            printf("Number of columns in A:");
            scanf("%d", &A.col);
            allocate(&A);

            printf("\n");
            printf("Number of rows in B:");
            scanf("%d", &B.row);
            printf("Number of columns in B:");
            scanf("%d", &B.col);
            allocate(&B);

         break;
         case 2:
            printf("A + B=\n");

            add_matrix(&A, &B);

            break;
         case 3:
            printf("A - B=\n");

            sub_matrix(&A, &B);

            break;
         case 4:
            printf("ddd\n");
            break;
         case 5:
            return 0;
            break;
         default:
            printf("Not a valid input. Try again.\n");
            break;
      }

   }
      return 0;
}

Se trata de una calculadora de matrices que suma, resta y multiplica. Tengo hechos todos los casos menos el de multiplicar, que no tengo ni idea de como hacerlo. Alguno podria echarme una ayudita?? En los requisitios me dice que tiene que ser una funcion que use punteros a estructuras o estructuras como en el caso de la suma y la resta. POR FAVOR ES MUY IMPORTANTE Y URGENTE, me juego mucha nota. Estaria eternamente agradecido de cualquier ayuda.

Antonio

16
C/C++ / Re: Ayuda Con Unix Help System
« en: Miércoles 3 de Diciembre de 2003, 13:28 »
Gracias pero al final descubri que la lbireria string.h tiene una funcion mu "bonika":P q se llama strcmp y que compara 2 strings, asi que al final me salio mucho mas facil! Aqui dejo el codigo: (x si alguien necesita algo parecido)

   printf("Enter command name to look up:");
                scanf("%s", com2);
   for(i=0; i<6; i++)
   {
          t= strcmp(com2[0], commands);
          if(t==0)
      printf("%s %s\n", commands, descriptions);   
   }

Declarando t como integer. Espero que a alguien le sirva de ayuda;)

Ahora mi problema es el apartado 2 :( no tengo ni idea de como hacerlo, agradeceria cualkier ayuda.

17
C/C++ / Ayuda Con Unix Help System
« en: Martes 2 de Diciembre de 2003, 15:45 »
Bueno, esto es lo que me piden, se como se hace en general, solo necesito que me ayudeis en como hago para que cuando salga esto:

Introduce el comando que quieres ver su descripcion: cd

Me salga esto, todo con strings multidimensionales.
cd - command directory

aki teneis la descripcion del programa x si acaso(esta en ingles)

B. Write a program to implement an interactive help system, to train users in the “Unix” operating system. The following example gives the Unix command names that will be stored in the help system, together with their description. You do not need any knowledge of Unix to write the program.

Command   Description
ls                list files in a directory
cd              change directory
mv              rename or move files to another directory
cp               copy files
rm              delete files
more          display the contents of files

Your program should be able to carry out the operations as outlined in the menu below. See below for sample output. Output for options 3 and 4 should be of similar format. Your program should generate an error message if the user enters a menu option other than 1-5.

Welcome to the Unix help system.
1 - look up a command
2 - search for words in the description
3 – display all commands
4 – display all commands and descriptions
5 - quit

Your choice: 1

Enter command name to look up: cd
cd - change directory

Your choice: 2

Enter a word to search for: directory
The following entries contain the word 'directory':
ls
cd
mv
.
.
.
Your choice: 5

End of program

Hint: The commands and descriptions should each be stored as strings, at initialisation.
The command strings should be stored in one array and the descriptions should be stored in another.
------------------

Entiendo la estructura perfectamente, con un switch keda perfecto pero es problema es que no se como hacerlo con los arrays que me piden, alguna sugerencia x favor? Me juego la nota de un semestre!!

18
C/C++ / SOCORRO AYUDA URGENTE CON UN PROGRAMA DE MEDICION DE TEMPERA
« en: Martes 18 de Noviembre de 2003, 03:38 »
Muchas gracias, la verdad es que me has salvado el cuello porque este era un trabajo de la uni que me llevo comiendo el coco 5 dias y no encontraba la solucion. Muchas gracias en serio!

19
C/C++ / Re: SOCORRO AYUDA URGENTE CON UN PROGRAMA DE MEDICION DE TEM
« en: Lunes 17 de Noviembre de 2003, 18:48 »
Me piden que haga un programa que al introducirle una serie de temperaturas, las que sean, (scanf), me diga cuantas veces he introducido esa temperatura mediante la siguiente tabla:

Datos introducidos: 0, 0, 1, 2, 3, ,3

- 0 grados 2 veces
- 1 grados 1 veces
- 2 grados 1 veces
- 3 grados 2 veces
.
.
.
-40 grados x veces

Asi hasta 40. Pero el problema es q tengo q acerlo usando arrays. Lo q llevo asta aora os lo pongo aki, ahi sale todo emjor explicado aunque esta en ingles:(tambien estan hechas las 2 primeras partes del programa que me pedian hallar cuantas veces era superior a 30C y cuantas igual a 19C)

#include <stdio.h>

int main (void)

{
   /* Declaring the integers */
   int temp[41];
   int input=0, T=0, n, m;
    int day=0, day2=0, C=0, day3=0;

   printf("Temperature Readings Program.n");
   printf("By Antonio Medina.n");
   printf("MS-DOS Version 1.0n");
   printf("-----------------------------n");
   printf("n");
   printf("Enter temperature readings:n");
   
   while(T!=-999) // Declaring the while loop, as long as Temperature is not -999 it works.
      
   {   
      scanf("%d", &T);
       if((T<0)&&(T>-999))// If the value is negative this 'if' will set it to 0.
      {
          printf("Your value has been set to 0n");
         T=0;
      }
       else if(T>40)// If the value is bigger than 40, this 'if' will set it to 40.
      {
          printf("Your value has been set to 40n");
         T=40;
      }

      temp[input]=T;
      input+=1;
   }
   

    for(n=0; n<=input-2; n++)// With this 'for' loop we are calculating the times
   {
         if(temp[n]>30)
           day=day+1;

   }   
   
   printf("n");
    printf("***Days greater than 30C =%d***n", day);

    for(m=0; m<=input-2; m++)
   {
        if(temp[m]==19)
          day2=day2+1;

   }
   printf("n");
    printf("***Days equal to 19C =%d***n", day2);

    //HASTA AQUI ES DONDE LLEGO, MAS ABAJO SON SOLO INTENTOS MIOS.
   for(C=0; C<41; C++)
   {
      if(temp[input]=C)
         day3=day3+1;
      printf("%dC in %d daysn", C, day3);

   }
      
   
   return 0;
}

20
C/C++ / Re: SOCORRO AYUDA CON UN PROGRAMA DE MEDICION DE TEMPERATURA
« en: Lunes 17 de Noviembre de 2003, 18:40 »
Me piden que haga un programa que al introducirle una serie de temperaturas, las que sean, (scanf), me diga cuantas veces he introducido esa temperatura mediante la siguiente tabla:

Datos introducidos: 0, 0, 1, 2, 3, ,3

- 0 grados 2 veces
- 1 grados 1 veces
- 2 grados 1 veces
- 3 grados 2 veces
.
.
.
-40 grados x veces

Asi hasta 40. Pero el problema es q tengo q acerlo usando arrays. Lo q llevo asta aora os lo pongo aki, ahi sale todo emjor explicado aunque esta en ingles:(tambien estan hechas las 2 primeras partes del programa que me pedian hallar cuantas veces era superior a 30C y cuantas igual a 19C)

#include <stdio.h>

int main (void)

{
   /* Declaring the integers */
   int temp[41];
   int input=0, T=0, n, m;
    int day=0, day2=0, C=0, day3=0;

   printf("Temperature Readings Program.n");
   printf("By Antonio Medina.n");
   printf("MS-DOS Version 1.0n");
   printf("-----------------------------n");
   printf("n");
   printf("Enter temperature readings:n");
   
   while(T!=-999) // Declaring the while loop, as long as Temperature is not -999 it works.
      
   {   
      scanf("%d", &T);
       if((T<0)&&(T>-999))// If the value is negative this 'if' will set it to 0.
      {
          printf("Your value has been set to 0n");
         T=0;
      }
       else if(T>40)// If the value is bigger than 40, this 'if' will set it to 40.
      {
          printf("Your value has been set to 40n");
         T=40;
      }

      temp[input]=T;
      input+=1;
   }
   

    for(n=0; n<=input-2; n++)// With this 'for' loop we are calculating the times
   {
         if(temp[n]>30)
           day=day+1;

   }   
   
   printf("n");
    printf("***Days greater than 30C =%d***n", day);

    for(m=0; m<=input-2; m++)
   {
        if(temp[m]==19)
          day2=day2+1;

   }
   printf("n");
    printf("***Days equal to 19C =%d***n", day2);

    //HASTA AQUI ES DONDE LLEGO, MAS ABAJO SON SOLO INTENTOS MIOS.
   for(C=0; C<41; C++)
   {
      if(temp[input]=C)
         day3=day3+1;
      printf("%dC in %d daysn", C, day3);

   }
      
   
   return 0;
}

Páginas: [1]