NEWBIE please help with strcpy..

This is a discussion on NEWBIE please help with strcpy.. within the C++ Programming forums, part of the General Programming Boards category; i am simply trying to copy an array into the first element of an array of strings... i have, generically... ...

  1. #1
    drdeepz
    Guest

    Unhappy NEWBIE please help with strcpy..

    i am simply trying to copy an array into the first element of an array of strings...

    i have, generically...

    char A[100] = " ";
    char *B[100] = {};

    i am trying to copy the full contents of A , into B[0]

    i have tried....
    B[0] = A;
    which doesnt help, just points A to B[0]

    and
    strcpy(B[0], A)
    does not work either. no errors, but get seg fault

    please help!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >char *B[100]
    This is an array of pointers, it is not an array of chars. Before you can strcpy() to it, you need to point the pointers somewhere useful.

    As you're just beginning, I'd suggest you do something more like this:
    >char B[10][100];
    which will give you space for 10 strings, each 100 long (including the NULL terminator.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  2. Strcpy
    By Godders_2k in forum C Programming
    Replies: 17
    Last Post: 12-12-2007, 12:34 PM
  3. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 06:14 PM
  4. Question about strcpy
    By Kevinmun in forum C Programming
    Replies: 4
    Last Post: 11-02-2005, 11:00 PM
  5. Help Please, Newbie
    By chris2k5 in forum C Programming
    Replies: 9
    Last Post: 01-29-2005, 10:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21