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

This is a discussion on How can I copy a "char *" to a "char"... within the C Programming forums, part of the General Programming Boards category; Question: How can I copy a variable declared as a "char *" to a variable declared as either an "int" ...

  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,386
    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, 03:21 PM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 10:15 AM

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