Thread: array prob

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 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, 07:01 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Char Array Prob
    By hern in forum C Programming
    Replies: 7
    Last Post: 07-28-2003, 10:44 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM