int ishexaoctacasdemerde(t_opts *opts) { if ((ishexa(opts) && opts->flags['#'] && !opts->flags['0']) || (isocta(opts) && opts->flags['#'] && !opts->flags['0'])) return (1); return (0); }
int isptrand0orishexaandsharpand0(t_opts *opts) { if ((opts->type == 'p' && opts->flags['0']) || (ishexa(opts) && opts->flags['#'] && opts->flags['0'])) return (1); return (0); }
int scanf(const char * fmt, ...){ va_list ap; //apunta a cada arg sin nombre en orden char *p, *sval, *cval; int *ival; FILE fp; int read=0,i=0, c,k, j = 0; va_start(ap, fmt); //hace que ap apunte al 1er arg sin nombre char s[BUFFER_SIZE]; while((c = getchar()) != '\n' && i < BUFFER_SIZE) { if(c!=0){ if(c == '\b' && i >= 1){ i--; putc(c ,(FILE*)1); } if(c != '\b' && c!='\n'){ s[i] = c; i++; putc(c ,(FILE *)1); } } } s[i] = '\0'; i = 0; for (p = (char*)fmt; *p; p++) { char aux [BUFFER_SIZE] = {0}; if(*p != '%') { c = s[j++]; if(c =='\0' || *p != c) return read; continue; } switch (*++p) { case 'd': i=0; ival = va_arg(ap,int *); while(s[j] != '\0' && isdigit(s[j])) { aux[i++] = s[j++]; } aux[i] = '\0'; if(aux[0] == '\0') return read; *ival=atoi(aux); read++; break; case 's': i = 0; sval = va_arg(ap,char *); while(s[j] != '\0' && s[j] != ' ') { aux[i++] = s[j++]; } aux[i] = '\0'; if(aux[0] == '\0') return read; k = 0; while(aux[k] != '\0') { sval[k] = aux[k]; k++; } sval[k] = '\0'; read++; break; case 'c': cval = va_arg(ap,char*); c = s[j++]; if(c == '\0' ) return read; *cval = c; read++; break; case 'x': i=0; ival = va_arg(ap,int *); while(s[j] != '\0' && (isdigit(s[j]) || ishexa(s[j]))) { aux[i] = s[j]; i++; j++; } aux[i] = '\0'; if(aux[0] == '\0') return read; //*ival=ato(aux, i, 16); read++; break; default: c = s[j++]; if(!(c != EOF && c != '\n' && *p == c)) return read; break; } } va_end(ap); // clean up when done return read; }