C/Visual C - por favor, ayuda urgente!! programa casi terminado

 
Vista:

por favor, ayuda urgente!! programa casi terminado

Publicado por rodrigo (2 intervenciones) el 13/08/2012 01:54:53
hola, necesito terminar este codigo para hoy y estoy desesperado, no esta funcionando, compila bien, pero cuando le doy la orden ./programa <texto1.csv>texto2.csv se queda con el cursor titilando en el shell y el archivo generado queda vacio

la idea es que tome un "texto1.csv" como este:
r0001023, PÉREZ Juan, Física, 8
s25418-2, DOMÍNGUEZ Domingo, Literatura, 9
w0412346, FULANO Fidel, Física, 10
q23411-t, ZUTANO Jose, Geografía, 7
w0412345, MENGANO Pedro, Física, 10

y lo separe en varios vectores para luego imprimir para cada persona su promedio, nota maxima y nota minima en el texto2.csv





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <stdio.h>
 
#define MAX_ALU 15
#define MAX_LINE 80
#define MAX_LEGAJO 8
#define MAX_NOMBRE 40
#define MAX_MATERIA 15
 
 
void Ingreso(char texto_in [][MAX_LINE], int max_alu,int max_line);
int convert (char texto_in [][MAX_LINE], char legajos [][MAX_LEGAJO], char nombres [][MAX_NOMBRE], int notas []);
int char_a_int (char texto_in [][MAX_LINE],int posicion_i, int posicion_j,int error);
int comparar (char str1 [][MAX_LEGAJO],int posicion_i1, int posicion_i2);
float promedio (char legajos [][MAX_LEGAJO],int notas[],int i1);
int min (char legajos[][MAX_LEGAJO], int notas [],int i1);
int max (char legajos[][MAX_LEGAJO], int notas [],int i1);
void Imprimir (char legajos[][MAX_LEGAJO], char nombres [][MAX_NOMBRE], int notas []);
 
 
int main ()
{
  char texto_in [MAX_ALU][MAX_LINE];
  char legajos [MAX_ALU][MAX_LEGAJO], nombres [MAX_ALU][MAX_NOMBRE];
  int notas [MAX_ALU];
  int devolver=0;
 
  Ingreso(texto_in,MAX_ALU,MAX_LINE);
  devolver=convert(texto_in,legajos, nombres, notas);
  Imprimir(legajos,nombres,notas);
 
  return devolver;
 
}
//Funcion Ingreso
void Ingreso(char texto_in [][MAX_LINE], int max_alu,int max_line)
{
  int i=0,j=0,c;
  char aux[max_alu][max_line];
  c=getchar();
  while ((c != EOF) && (i<max_alu))
  {
    while ((c!='\n') && (j<max_line))
    {
      texto_in[i][j]=c;
      j++;
      c=getchar();
    }
    i++;
    c=getchar();
  }
  texto_in[i][j]='\0';
 
}
 
 
//Funcion convert, se fija tambien si no hay suficientes datos(menos de 3 comas)
int convert (char texto_in [][MAX_LINE], char legajos [][MAX_LEGAJO], char nombres [][MAX_NOMBRE], int notas [])
{
  int i=0,j=0,comas=0,error=0,j2;
  while (texto_in[i][j]!= '\0' && (i<MAX_ALU))
  {
   while (texto_in[i][j]!=','&& (j<MAX_LINE))	//cargo los legajos en una nueva variable
   {
    legajos[i][j]=texto_in[i][j];
    j++;
   }
 
   if(texto_in[i][j]==',') 		//comprueba que el caracter sea una coma y no el maximo de linea
     comas++;
 
   j++;
 
   while(texto_in[i][j]==' ')		//comprueba que el proximo caracter no sea un espacio
    j++;
 
   while (texto_in[i][j]!=','&& (j<MAX_LINE))	//cargo los nombres en una nueva variable
   {j2=0;
    nombres[i][j2]=texto_in[i][j];
    j++;
    j2++;	//uso otra variable porque no estan la misma posicion
   }
 
   if(texto_in[i][j]==',')
     comas++;
 
   j++;
 
   while(texto_in[i][j]==' ')
    j++;
 
   while(texto_in[i][j]!=',' && (j<MAX_LINE))	//salto los espacios porque no interesa saber las materias de las notas
    j++;
 
   if(texto_in[i][j]==',')
     comas++;
   j++;
   while(texto_in[i][j]==' ')
    j++;
 
   notas[i]=char_a_int(texto_in, i, j,error);
   i++;
   j=0;
   if(comas!=3)		//si hay menos de tres comas decrementa la variable error, para que sue devuelva un valor negativo si hay algun error
     error--;
   comas=0;		//vuelvo a establecer 0 comas para la proxima linea
  }
  legajos[i][j]='\0';
  nombres[i][j]='\0';
  notas[i]='\0';
  return error;
}
 
//Funcion char_a_int
int char_a_int (char texto_in [][MAX_LINE],int posicion_i, int posicion_j,int error)
{
  int aux=0,nota=0;
  while(texto_in[posicion_i][posicion_j]!='\n')
    aux++;
  if(aux==2)
    nota=(texto_in[posicion_i][posicion_j]-'0')*10+(texto_in[posicion_i+1][posicion_j+1]-'0');
  if (aux==1)
    nota=(texto_in[posicion_i][posicion_j]-'0');
  if(aux!=2 && aux!=1)
    error--;
  return nota;
 
}
 
//Funcion comparar, compara legajos y si son iguales devuelve 0
 
int comparar (char str1 [][MAX_LEGAJO], int posicion_i1,int posicion_i2)
{
  int comparacion=0,j=0;
  while(str1[posicion_i1][j]!='\0' && j<MAX_LEGAJO && str1[posicion_i2][j])
  {
    comparacion=comparacion+(str1[posicion_i1][j]-str1[posicion_i2][j]);
    j++;
  }
  return comparacion;
}
 
 
//Funcion promedio
float promedio (char legajos [][MAX_LEGAJO],int notas[],int i1)
{
  int i2,cantidad=0,suma=0;
  float promedio;
 
  suma=notas[i1];
  cantidad++;
  for(i2=i1+1;legajos[i2][0]!='\0';i2++)
  {
    if(comparar(legajos,i1,i2)==0)
    {
      suma=suma+notas[i2];
      cantidad++;
    }
  }
  promedio=suma/cantidad;
  return promedio;
}
 
//Funcion maximo
int max (char legajos[][MAX_LEGAJO], int notas [],int i1)
{
  int i2,max;
 
  max=notas[i1];
  for(i2=i1+1;legajos[i2][0]!='\0';i2++)
  {
    if(comparar(legajos,i1,i2)==0 && notas[i2]>max)
    {
      max=notas[i2];
    }
  }
  return max;
}
 
//Funcion minimo
int min (char legajos[][MAX_LEGAJO], int notas [],int i1)
{
  int i2,min;
 
  min=notas[i1];
  for(i2=i1+1;legajos[i2][0]!='\0';i2++)
  {
    if(comparar(legajos,i1,i2)==0 && min>notas[i2])
    {
      min=notas[i2];
    }
  }
  return min;
}
 
//funcion imprimir
void Imprimir (char legajos[][MAX_LEGAJO], char nombres [][MAX_NOMBRE], int notas [])
{
  int i1=0,i2,aux=0;
 
  printf("%s, %s, promedio:%.2f, maximo:%d y minimo:%d\n",legajos[i1],nombres[i1],promedio(legajos,notas,i1),max(legajos,notas,i1),min(legajos,notas,i1));
  i1++;
  while(legajos[i1][0]!='\0')
  {
    for(i2=i1-1;i2>=0;i2--)
    {
      aux=aux+comparar(legajos,i1,i2);
    }
    if(aux==0)
      printf("%s, %s, promedio:%.2f, maximo:%d y minimo:%d\n",legajos[i1],nombres[i1],promedio(legajos,notas,i1),max(legajos,notas,i1),min(legajos,notas,i1));
    aux=0;
    i1++;
  }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

por favor, ayuda urgente!! programa casi terminado

Publicado por Tom (619 intervenciones) el 13/08/2012 09:23:13
No sé si habrá más problemas, pero el primero es que te has olvidado de reinicializar a 0 el indice de las frases. Te lo marco en tu codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Funcion Ingreso
void Ingreso(char texto_in [][MAX_LINE], int max_alu,int max_line)
{
  int i=0,j=0,c;
  char aux[max_alu][max_line];
  c=getchar();
  while ((c != EOF) && (i<max_alu))
  {
    while ((c!='\n') && (j<max_line))
    {
      texto_in[i][j]=c;
      j++;
      c=getchar();
    }
    i++;
    j = 0; /* AQUI REINICIAS */
    c=getchar();
  }
  texto_in[i][j]='\0';
 
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

por favor, ayuda urgente!! programa casi terminado

Publicado por rodrigo (2 intervenciones) el 15/08/2012 17:17:45
gracias amigo, ya es tarde para la entrega, pero valoro tu respuesta y voy a terminar este programa para acabar de entender este tema, saludo!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar