invalid initializer

This is a discussion on invalid initializer within the C Programming forums, part of the General Programming Boards category; PHP Code: char result [] =  concat (( char ) area_camada , "-" ,( char ) boxes_camada , "-" ,( char ) ...

  1. #1
    Banned
    Join Date
    Mar 2008
    Posts
    78

    invalid initializer

    PHP Code:
    char result[] = concat((char)area_camada,"-",(char)boxes_camada,"-",(char)wires_camada,"]"); 
    invalid initializer
    Why?

  2. #2
    Banned
    Join Date
    Mar 2008
    Posts
    78
    With this i want a result like this for example lets assume that:
    int area_camada = 33
    int boxes_camada = 45
    int wires_camada = 8533

    The result would be:
    "33-45-8533]"

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Use sprintf?
    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.*

  4. #4
    Banned
    Join Date
    Mar 2008
    Posts
    78
    Quote Originally Posted by Dave_Sinkula View Post
    Use sprintf?
    dont know that function, can you make this script with it?
    Can i store sprintf in an array[n] ?

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Milhas View Post
    dont know that function, can you make this script with it?
    Can i store sprintf in an array[n] ?
    This is what sprintf was designed to do, so of course it works for this sort of thing. Yes the "output" of sprintf can be put in a char array.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    sprintf works just like printf, except it has a first argument that is a char pointer (or array) that is the destination, instead of the "console" where printf normally ends up.

    So if you know how to print the string using printf, then all you need to do is change it like this:
    Code:
    #include <stdio.h>
    
    int main()
    {
       char buf[100];
       printf("Hello, World!\n");
       sprintf(buf, "Hello, World from sprintf\n");
       printf("%s", buf);
       return 0;
    }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Banned
    Join Date
    Mar 2008
    Posts
    78
    Thanks that solves my problem!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. invalid initializer
    By dr$brown in forum C Programming
    Replies: 8
    Last Post: 01-02-2005, 09:44 AM

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