Thread: Questions..

  1. #16
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by argv View Post
    by the way, is: "char *name" the same as "char name[]";
    Nope! the former is a pointer while the latter is an array.
    Quote Originally Posted by argv View Post
    I dunno, but I like 'int* p' for some wierd reason. I guess as long as your consistent, it doesn't matter.
    I think there's a link in the faq section on programming style which would be helpful.

  2. #17
    Registered User
    Join Date
    May 2009
    Posts
    29

    hmm..

    Quote Originally Posted by laserlight View Post
    In this context, no. The former declares name as a pointer to char, the latter declares name as an array of char with the size determined by the initialiser.
    ok, so just so I'm clear, did you mean "less than" when you wrote this? (it seems like you would mean "more than"?

    Quote Originally Posted by laserlight View Post
    Somewhat, except that you do not know if argv[1] actually has less than 20 characters, so strcpy() risks buffer overflow.
    Unless that is something with the strcpy function copying a string that is smaller than the array. But I thought if I make an array 20, then it will just copy whatever is 20 or less.

    This is alot less automatic than those higher level languages.

  3. #18
    Registered User
    Join Date
    May 2009
    Posts
    29
    Quote Originally Posted by itCbitC View Post
    Nope! the former is a pointer while the latter is an array.

    I think there's a link in the faq section on programming style which would be helpful.
    Oh, thanks. I added that to my favorites list. And now I know what the hell a "foo" is I gues. cool.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by argv
    Unless that is something with the strcpy function copying a string that is smaller than the array. But I thought if I make an array 20, then it will just copy whatever is 20 or less.
    strcpy() copies from the source to the destination until a null character is encountered. So, suppose the destination array is an array of 20 characters, including one character reserved for the null character. Supposed argv[1] contains all the letters of the English alphabet. There is not enough space to store the contents of argv[1] in the destination array, so strcpy() will keep copying, even if it means writing into memory that it should not be writing to.
    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

  5. #20
    Registered User
    Join Date
    May 2009
    Posts
    29

    ah

    Quote Originally Posted by laserlight View Post
    strcpy() copies from the source to the destination until a null character is encountered. So, suppose the destination array is an array of 20 characters, including one character reserved for the null character. Supposed argv[1] contains all the letters of the English alphabet. There is not enough space to store the contents of argv[1] in the destination array, so strcpy() will keep copying, even if it means writing into memory that it should not be writing to.
    Ok, gotcha. thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM