Skip to content

Instantly share code, notes, and snippets.

@sebastianlujan
Created March 8, 2018 23:40
Show Gist options
  • Save sebastianlujan/15a643f8cc1517c2c55c9a2031b4b8f8 to your computer and use it in GitHub Desktop.
Save sebastianlujan/15a643f8cc1517c2c55c9a2031b4b8f8 to your computer and use it in GitHub Desktop.
reads the standar i/o.
info_t leer_info(int max){
info_t leido;
int num;
char *cadena = new char[max + 1];
char simbolo;
bool error = false;
scanf(" %c", &simbolo);
if (simbolo != '(')
error = true;
else {
scanf("%d", &num);
scanf("%c", &simbolo);
if (simbolo != ',')
error = true;
else {
int pos = 0;
int c = getchar();
while ((c != ')') && (c != '\n')) {
cadena[pos] = c;
pos++;
c = getchar();
}
cadena[pos] = '\0';
if (c == '\n' ){
error = true;
ungetc('\n', stdin);
}
}
}
if(error){
char *nulo = new char[1];
nulo[0] = '\0';
leido = crear_info(INT_MAX, nulo);
} else {
char *frase = new char[strlen(cadena) + 1];
strcpy(frase, cadena);
leido = crear_info(num, frase);
}
delete[] cadena;
return leido;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment