How many parameters can I pass by reference in C++, without getting abnormal behavior -


i had problem function:

int parsearrestricciones(char linea[], unsigned int& x, unsigned int& y, unsigned int& tiempo, char restric[]) 

inside function parse linea[].

the input consists in: 3 unsigned integers, , string of punctuation characters. need read them way. problem ocurrs when assign atoi(linea+offset) variable tiempo. outside function (i.e., in main() ), value of tiempo not same it's inside. had problem tiempo (i replaced x,y , tiempo pointer struct. works)

what problem?

thanks help.

-----edit-again

the full code:

#include <iostream> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <cassert>  #define max_restric 3  // tres sentidos. si hay 4, se usa '+' #define max_linea 80 #define entrada cin   using namespace std;  int parsearrestricciones(char *linea, unsigned int& x, unsigned int& y, unsigned int& t, char *restric) { // ! solo funciona si x,y,t,restric estan en una misma linea (i.e. no hay cr lf)  int i=0, j=0;  //parsea x de la casilla x = atol(linea+i);//strtol(linea,(char**)null,10);  while (isdigit(linea[i])) i++; while (isspace(linea[i])) i++;  //parsea y de la casilla y = atol(linea+i);  while (isdigit(linea[i])) i++; while (isspace(linea[i])) i++; if(linea[i] == '\0')     return -1;  //parsea tiempo t = atol(linea+i); cout << "---" << t << endl;  while (!ispunct(linea[i])) i++;  //parsea restricciones while (linea[i] != '\0' && linea[i] != ' '){     restric[j] = linea[i];     i++; j++; } restric[j]='\0';  return 1;  }   int main (int argc, char** argv) { // sugerencia de argumentos // --d  (por dijkstra) // --axe  (por a*, distancia euclideana) // --axm  (por a*, distancia manhattan)  // y dos màs que veremos luego :)  unsigned int x, y; unsigned int xi, yi; unsigned int xf, yf;  unsigned int x,y,tiempo;  char restricciones[max_restric + 1];   //buffer para parsear las lineas con restricciones char linea[max_linea + 1];  bool fincasos = false; bool siguientecaso = false;   while (!fincasos) {      if (siguientecaso){         // se leyó otro mapa antes que éste (hubo parseo, y quedo en xcasilla,ycasilla)         x = x;         y = y;         siguientecaso = false;      } else {         // sino, lee por primera vez las dimensiones del mapa         entrada >> x >> y;     }      if ( x == 0  &&  y == 0 )         fincasos = true;      else {          entrada >> xi >> yi;          entrada >> xf >> yf;          // lee restricciones hasta que encuentra una linea sin ellas (sin tiempo ni direccion)         // se asumira, que corresponde las dimensiones del siguiente caso, y los usará en la siguiente         // iteracion         while(!siguientecaso) {              cin.get(); //lee un '\0' que quedó (?)             cin.getline(linea, max_linea+1);              if ( parsearrestricciones(linea,x,y,tiempo, restricciones) == -1 ) {                 siguientecaso = true;              } else {                  cout << "x = " << x << endl;                 cout << "y = " << y << endl;                 cout << "tiempo = " << tiempo << endl;                 cout << "restric = " << restricciones << endl;                 int j=0;                 cout << "restric = " ;                 while(restricciones[j]!='\0'){                     cout << restricciones[j];j++;}                 cout << endl;                  //-- agregar datos al grafo/mapa             }          }          // resolver usando algun algoritmo         //--- resolver(mapa)      }  }   return 0; } 

cflags. -wall -pipe -g -ggdb -donline_judge -dndebug (the makefile builds source, uvaonlinejudge)

input:

101 10 1 1 2 2 1000 10000  100000 +++++ 

output:

---100000 x = 1000 y = 10000 tiempo = 65579 restric = +++++ restric = +++++ ^x^c (i did break) 

i tested program in windows (using code::blocks, default settings) , worked :/

by way, i'm using ubuntu in virtualbox

could tell me i'm doing wrong?

how many parameters can pass reference in c++, without getting abnormal behavior?

as many want to!


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -