Thread: How can I copy a "char *" to a "char"...

  1. #1
    Unregistered
    Guest

    Question How can I copy a "char *" to a "char"...

    Question:
    How can I copy a variable declared as a "char *" to a variable declared as either an "int" or "char" and print it out to verify it did it properly? Any help would be greatly appreciated.
    Alex

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Can you expand your question and give an example?

    here's an attempt to answer in the meantime:
    Code:
    char *p = "blurb";
    char c;
    
    c = *p;
    putchar (c);
    ---------------
    char *p = "11";
    int i;
    i = atoi(p);
    printf ("%d", i);
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Unregistered
    Guest
    Hammer,
    Here's what I'm trying to do.

    typedef struct PLANE_STRUCT {
    char North_Airfields[158];
    } PLANETYPE;

    char *bb[5];

    pPlane.North_Runway[M] = bb[4];

    printf("Runway = %s\n", pPlane.North_Runway[M]);

    When I compile the code I get the warning,
    warning C4047: '=' : 'char ' differs in levels of indirection from 'char *'

    When I run this code it aborts.

    Thanks!

  4. #4
    Unregistered
    Guest

    Smile

    Hammer,
    I figured out what I was doing wrong.
    Thanks for your help!

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    pPlane.North_Runway[M] is not a string but the M-th character of the string North_Airfields.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying constant amount of data
    By TriKri in forum C++ Programming
    Replies: 16
    Last Post: 07-12-2008, 06:32 AM
  2. calling copy constructor from template
    By Ancient Dragon in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2005, 01:54 PM
  3. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  4. Copy Constructor crashing program
    By bob2509 in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2002, 04:21 PM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 11:15 AM