strcpy problem

This is a discussion on strcpy problem within the C++ Programming forums, part of the General Programming Boards category; I have the following code, and am trying to copy an array of charactes from one variable to another: Code: ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    10

    Thumbs down strcpy problem

    I have the following code, and am trying to copy an array of charactes from one variable to another:
    Code:
    char name[15];
    int age;
    
    cout << "Name:";
    cin.getline(n, 15);
    cout << "Age:"; cin >> a;
    
    age = a;
    strcpy(name, n);
    "name" is declared somewhere else in the program, as char[15]..

    The error i'm getting is that "strcpy" is an undeclared identifier.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,674
    Have you put #include <cstring> at the top of your program?
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,439
    Or just write one for fun.

    Code:
    char * strcpy(char * target, char * source){
    char * index = target; 
     while(*source != 0)       { 
      *(index++) = *(source++);
     }
    *index = 0;
    return target;
    }
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's up with this strcpy?
    By fanoliv in forum C Programming
    Replies: 7
    Last Post: 06-19-2006, 05:24 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM

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