simple question

This is a discussion on simple question within the C Programming forums, part of the General Programming Boards category; I have a really simple problem. I forgot how to assign a message to a string with a counter. I ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    9

    simple question

    I have a really simple problem.
    I forgot how to assign a message to a string with a counter.

    I thought it was something like this:
    Code:
    startunit[i] = "mm";
    but it does not work


    Any help tonight would be great. I have a program due in 12 hrs, and this is the main problem right now.

    thanks.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    strcpy(startunit[i], "mm");
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    9
    When I tried
    Code:
    strcpy(startunit[i], "mm");
    I got the error
    Code:
    83 C:\Dev-Cpp\final.c [Warning] passing arg 1 of `strcpy' makes pointer from integer without a cast
    I defined the string as
    Code:
    char startunit [5];

  4. #4
    .
    Join Date
    Nov 2003
    Posts
    307
    strcpy(startunit,"mm");

    or

    strcpy(&startunit[3],"mm");

    The second one will probably create garbage in front of the "mm"

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    or this
    Code:
    startunit[i]='m'
    startunit[i+1]='m'
    Of course i must be incrimented by at least 2 eah iteration otherwise you would be overwriting the second char.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 09:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2005, 12:41 AM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM

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