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,806
    Have you put #include <cstring> at the top of your program?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 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, 06:24 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM
  5. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 07:24 PM

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