On Mon, Aug 14, 2017 at 05:09:00AM -0700, Doğan Kurt wrote: > I want to do something analogous to this C code. > > c = getchar() > > if (isdigit(c)) { > ungetc(c, stdin); > scanf("%d", &num); > } > > In fmt package, fmt.Scanf("%d", &num) exists but ungetc doesn't exist. For > bufio package, Peek function exists which is great but there is no ReadInt.
Consider combining using the bufio package and scanning form a buffered reader using fmt.Fscanf(). Please see the documentation on the fmt package and notice that the function it exports come in packs where the first letter of the name of each function in such a pack indicates ... For instance: - Print() just prints to os.Stdout, Printf() is "print formatted". - Fprint() is "file print" -- it outputs to the specified io.Writer. - Sprint() is "string print" -- it outputs to a string. The pack of functions to do scanning roughly conforms to the same idea: - Scan() scans from os.Stdin. - Scanf() is "scan formatted". - Fscan() scans from the specified io.Reader. - Sscan() scans from a string. ... -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.