Thread: Comparing strings - beginner question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This:
    Code:
    char a[2] = {"A"};
    char c[2] = {"A"};
    char b[2] = {"A"};
    should be:
    Code:
    char a[2] = "A";
    char c[2] = "A";
    char b[2] = "A";
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    4
    Quote Originally Posted by laserlight View Post
    This:
    Code:
    char a[2] = {"A"};
    char c[2] = {"A"};
    char b[2] = {"A"};
    should be:
    Code:
    char a[2] = "A";
    char c[2] = "A";
    char b[2] = "A";

    I tried it and it works too. But what's the difference? When should I use the curly brackets? EDIT; When writing to an array?


    Also - should I upload the code for the finalized Tic Tac Toe for anyone interested in what I'm using this for?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [VERY Beginner question] Strings + functions + ...pointers?!
    By arthurhess in forum C++ Programming
    Replies: 4
    Last Post: 12-08-2009, 02:44 PM
  2. Beginner Question: Problem with scanf and strings. Help!
    By lucidrave in forum C Programming
    Replies: 8
    Last Post: 08-11-2009, 10:22 PM
  3. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  4. beginner question about strings
    By gp364481 in forum C Programming
    Replies: 4
    Last Post: 09-05-2008, 06:31 PM
  5. Comparing Strings
    By zdude in forum C Programming
    Replies: 1
    Last Post: 10-04-2002, 07:47 PM