FAQ
Can anyone find out what's wrong with this code? I didn't find the compiler
error very helpful.

package main

import "fmt"

func main(){
var x,y,z string
fmt.Printf("What's your name?")
fmt.Scanf("%s", &x)
fmt.Printf("What's the color of the sky?")
fmt.Scanf("%s", &y")
fmt.Printf("What's the opposite of down?")
fmt.Scanf("%s", &z)
fmt.Printf("%s %s %s. ;)", x, y, z")
}

The compiler output was...

# command-line-arguments
.\blewup.go:10: newline in string
.\blewup.go:11: syntax error: unexpected string literal, expecting )
.\blewup.go:13: newline in string
.\blewup.go:14: syntax error: unexpected string literal, expecting )

Thanks in advance.

--

Search Discussions

  • David Anderson at Nov 4, 2012 at 9:19 pm
    You have a syntax error on line 10. Remove the " after &y.

    - Dave
    On Sun, Nov 4, 2012 at 1:16 PM, ╚(•⌂•)╝ wrote:

    Can anyone find out what's wrong with this code? I didn't find the
    compiler error very helpful.

    package main

    import "fmt"

    func main(){
    var x,y,z string
    fmt.Printf("What's your name?")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?")
    fmt.Scanf("%s", &y")
    fmt.Printf("What's the opposite of down?")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z")
    }

    The compiler output was...

    # command-line-arguments
    .\blewup.go:10: newline in string
    .\blewup.go:11: syntax error: unexpected string literal, expecting )
    .\blewup.go:13: newline in string
    .\blewup.go:14: syntax error: unexpected string literal, expecting )

    Thanks in advance.

    --

    --
  • ╚(•⌂•)╝ at Nov 4, 2012 at 9:25 pm
    Thanks. I was fixing it as you found it. ^_^
    On Sunday, November 4, 2012 1:19:36 PM UTC-8, David Anderson wrote:

    You have a syntax error on line 10. Remove the " after &y.

    - Dave

    On Sun, Nov 4, 2012 at 1:16 PM, ╚(•⌂•)╝ <darkli...@gmail.com <javascript:>
    wrote:
    Can anyone find out what's wrong with this code? I didn't find the
    compiler error very helpful.

    package main

    import "fmt"

    func main(){
    var x,y,z string
    fmt.Printf("What's your name?")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?")
    fmt.Scanf("%s", &y")
    fmt.Printf("What's the opposite of down?")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z")
    }

    The compiler output was...

    # command-line-arguments
    .\blewup.go:10: newline in string
    .\blewup.go:11: syntax error: unexpected string literal, expecting )
    .\blewup.go:13: newline in string
    .\blewup.go:14: syntax error: unexpected string literal, expecting )

    Thanks in advance.

    --

    --
  • ╚(•⌂•)╝ at Nov 4, 2012 at 9:24 pm
    Nevermind. I realized I put quotes where they weren't appropriate. However,
    I'm still having issues. The new code follows.

    package main

    import "fmt"

    func main() {
    var x, y, z string
    fmt.Printf("What's your name?\n")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?\n")
    fmt.Scanf("%s", &y)
    fmt.Printf("What's the opposite of down?\n")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z)
    }

    First, it asks what my name is.
    I enter my name, and then it simultaneously asks what the color of the sky
    is, and what the opposite of down is. I enter blue, and then it says Alex
    blue. ;).

    Again, thanks in advance.
    On Sunday, November 4, 2012 1:16:24 PM UTC-8, ╚(•⌂•)╝ wrote:

    Can anyone find out what's wrong with this code? I didn't find the
    compiler error very helpful.

    package main

    import "fmt"

    func main(){
    var x,y,z string
    fmt.Printf("What's your name?")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?")
    fmt.Scanf("%s", &y")
    fmt.Printf("What's the opposite of down?")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z")
    }

    The compiler output was...

    # command-line-arguments
    .\blewup.go:10: newline in string
    .\blewup.go:11: syntax error: unexpected string literal, expecting )
    .\blewup.go:13: newline in string
    .\blewup.go:14: syntax error: unexpected string literal, expecting )

    Thanks in advance.
    --
  • David Anderson at Nov 4, 2012 at 9:30 pm

    On Sun, Nov 4, 2012 at 1:24 PM, ╚(•⌂•)╝ wrote:

    Nevermind. I realized I put quotes where they weren't appropriate.
    However, I'm still having issues. The new code follows.

    package main

    import "fmt"

    func main() {
    var x, y, z string
    fmt.Printf("What's your name?\n")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?\n")
    fmt.Scanf("%s", &y)
    fmt.Printf("What's the opposite of down?\n")

    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z)
    }


    First, it asks what my name is.
    I enter my name, and then it simultaneously asks what the color of the
    sky is, and what the opposite of down is. I enter blue, and then it says Alex
    blue. ;).
    The package documentation for "fmt" says the following, in the "Scanning"
    section of the overview:

    Scanf, Fscanf and Sscanf require newlines in the input to match newlines in
    the format; the other routines treat newlines as spaces.


    So, if you want to scan an entire line, your formats should be "%s\n".
    Otherwise, the first Scanf call doesn't read the newline at the end of your
    input, and that ends up being the value that the second Scanf receives.
    That's why your program skips straight to the 3rd Scanf.

    - Dave

    Again, thanks in advance.
    On Sunday, November 4, 2012 1:16:24 PM UTC-8, ╚(•⌂•)╝ wrote:

    Can anyone find out what's wrong with this code? I didn't find the
    compiler error very helpful.

    package main

    import "fmt"

    func main(){
    var x,y,z string
    fmt.Printf("What's your name?")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?")
    fmt.Scanf("%s", &y")
    fmt.Printf("What's the opposite of down?")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z")
    }

    The compiler output was...

    # command-line-arguments
    .\blewup.go:10: newline in string
    .\blewup.go:11: syntax error: unexpected string literal, expecting )
    .\blewup.go:13: newline in string
    .\blewup.go:14: syntax error: unexpected string literal, expecting )

    Thanks in advance.

    --
    --
  • ╚(•⌂•)╝ at Nov 4, 2012 at 9:37 pm
    What's your name?
    David
    What's the color of the sky?
    blue
    What's the opposite of down?
    up
    David blue up. ;)

    It works. Thank you very much. :)
    On Sunday, November 4, 2012 1:30:23 PM UTC-8, David Anderson wrote:

    On Sun, Nov 4, 2012 at 1:24 PM, ╚(•⌂•)╝ <darkli...@gmail.com <javascript:>
    wrote:
    Nevermind. I realized I put quotes where they weren't appropriate.
    However, I'm still having issues. The new code follows.

    package main

    import "fmt"

    func main() {
    var x, y, z string
    fmt.Printf("What's your name?\n")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?\n")
    fmt.Scanf("%s", &y)
    fmt.Printf("What's the opposite of down?\n")

    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z)
    }


    First, it asks what my name is.
    I enter my name, and then it simultaneously asks what the color of the
    sky is, and what the opposite of down is. I enter blue, and then it says Alex
    blue. ;).
    The package documentation for "fmt" says the following, in the "Scanning"
    section of the overview:

    Scanf, Fscanf and Sscanf require newlines in the input to match newlines
    in the format; the other routines treat newlines as spaces.


    So, if you want to scan an entire line, your formats should be "%s\n".
    Otherwise, the first Scanf call doesn't read the newline at the end of your
    input, and that ends up being the value that the second Scanf receives.
    That's why your program skips straight to the 3rd Scanf.

    - Dave

    Again, thanks in advance.
    On Sunday, November 4, 2012 1:16:24 PM UTC-8, ╚(•⌂•)╝ wrote:

    Can anyone find out what's wrong with this code? I didn't find the
    compiler error very helpful.

    package main

    import "fmt"

    func main(){
    var x,y,z string
    fmt.Printf("What's your name?")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?")
    fmt.Scanf("%s", &y")
    fmt.Printf("What's the opposite of down?")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z")
    }

    The compiler output was...

    # command-line-arguments
    .\blewup.go:10: newline in string
    .\blewup.go:11: syntax error: unexpected string literal, expecting )
    .\blewup.go:13: newline in string
    .\blewup.go:14: syntax error: unexpected string literal, expecting )

    Thanks in advance.

    --
    --
  • Archos at Nov 4, 2012 at 9:50 pm
    Hi! If you need questions to be answered by the user, this package could be
    helpful to you:

    http://go.pkgdoc.org/github.com/kless/terminal/quest

    Here you have some examples:
    https://github.com/kless/terminal/blob/master/quest/quest_test.go#L88

    El domingo, 4 de noviembre de 2012 21:16:24 UTC, ╚(•⌂•)╝ escribió:
    Can anyone find out what's wrong with this code? I didn't find the
    compiler error very helpful.

    package main

    import "fmt"

    func main(){
    var x,y,z string
    fmt.Printf("What's your name?")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?")
    fmt.Scanf("%s", &y")
    fmt.Printf("What's the opposite of down?")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z")
    }

    The compiler output was...

    # command-line-arguments
    .\blewup.go:10: newline in string
    .\blewup.go:11: syntax error: unexpected string literal, expecting )
    .\blewup.go:13: newline in string
    .\blewup.go:14: syntax error: unexpected string literal, expecting )

    Thanks in advance.
    --
  • ╚(•⌂•)╝ at Nov 4, 2012 at 10:01 pm

    Windows code is incomplete.
    I'll keep an eye on it.
    On Sunday, November 4, 2012 1:50:53 PM UTC-8, Archos wrote:

    Hi! If you need questions to be answered by the user, this package could
    be helpful to you:

    http://go.pkgdoc.org/github.com/kless/terminal/quest

    Here you have some examples:
    https://github.com/kless/terminal/blob/master/quest/quest_test.go#L88

    El domingo, 4 de noviembre de 2012 21:16:24 UTC, ╚(•⌂•)╝ escribió:
    Can anyone find out what's wrong with this code? I didn't find the
    compiler error very helpful.

    package main

    import "fmt"

    func main(){
    var x,y,z string
    fmt.Printf("What's your name?")
    fmt.Scanf("%s", &x)
    fmt.Printf("What's the color of the sky?")
    fmt.Scanf("%s", &y")
    fmt.Printf("What's the opposite of down?")
    fmt.Scanf("%s", &z)
    fmt.Printf("%s %s %s. ;)", x, y, z")
    }

    The compiler output was...

    # command-line-arguments
    .\blewup.go:10: newline in string
    .\blewup.go:11: syntax error: unexpected string literal, expecting )
    .\blewup.go:13: newline in string
    .\blewup.go:14: syntax error: unexpected string literal, expecting )

    Thanks in advance.
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 4, '12 at 9:16p
activeNov 4, '12 at 10:01p
posts8
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase