array prob

This is a discussion on array prob within the C++ Programming forums, part of the General Programming Boards category; I have a simple prob that I dont seem to be able to solve. The itemName is suppose to be ...

  1. #1
    Unregistered
    Guest

    Question array prob

    I have a simple prob that I dont seem to be able to solve. The itemName is suppose to be Item#....where # is to be the itemNum generated in the program.


    char itemName[MAX];
    int itemNum;
    ...
    ...
    strcpy(name, "Item");


    I have tried itemName[4]=itemNum but I get an ascii character where the number is suppose to be. Any suggestions?

    Thanx

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    sprintf( itemName, "Item%d", itemNum );

    And you don't even need the strcpy - it's all in one call

  3. #3
    Unregistered
    Guest
    Thanx for the reply but that wont work for me...firstly, I need to store the itemName and itemNum into a linked list for processing and secondly I need it in C++....cant have C

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    > firstly, I need to store the itemName and itemNum into a linked list
    Yeah, so what's your question?

    It's a simple char array with some characters in it, you never said it was a linked list.

    So its a linked list of char arrays, big deal - works either way.

    > I need it in C++....cant have C
    But you used strcpy - exactly how religious do you want to be?

  5. #5
    Unregistered
    Guest
    My fault...should have been more precise....let me rephrase the whole thing. I have a linked list with certain items in it. Two of these items are itemName[MAX] and itemNum.

    itemNum : generated in the program and used with itemName

    itemName : uses the value in itemNum e.g Item5 or Item200

    my prob is I cant read in the value from itemNum into itemName. I just need a method of doing it. Later in the program certain items are used and the search is done according to the itemName.

    Thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  2. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 08:01 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  4. Char Array Prob
    By hern in forum C Programming
    Replies: 7
    Last Post: 07-28-2003, 11:44 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM

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