Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 54
  1. #21
    C.I.A. Sarevok's Avatar
    Join Date
    Apr 2007
    Gender
    Male
    Posts
    2,802
    Blog Entries
    4

    [Programming Language]
    C/C++

    [Question]
    How do you convert a value defined in a macro into a string?
    Code:
    #define I_AM_NOT_A_STRING 666
    
    ...
    
    printf("%s\n",I_AM_NOT_A_STRING );
    The code above should give an output of "666".

  2. #22
    Change the format code %s to %d. [Hopeful guess! ] haha

  3. #23
    C.I.A. Sarevok's Avatar
    Join Date
    Apr 2007
    Gender
    Male
    Posts
    2,802
    Blog Entries
    4
    Quote Originally Posted by Moonfall View Post
    Change the format code %s to %d. [Hopeful guess! ] haha
    hehe that works pero wala nimo giconvert ang I_AM_NOT_A_STRING to a string nice try though hehe

    dapat siguro mag-add ko ug constraint na di hilabtan ang printf statement

    hint: do some macro manipulation

  4. #24
    Quote Originally Posted by Sarevok View Post
    hehe that works pero wala nimo giconvert ang I_AM_NOT_A_STRING to a string nice try though hehe

    dapat siguro mag-add ko ug constraint na di hilabtan ang printf statement

    hint: do some macro manipulation
    #define I_AM_NOT_A_STRING "666"

    Maybe?

  5. #25
    C.I.A. Sarevok's Avatar
    Join Date
    Apr 2007
    Gender
    Male
    Posts
    2,802
    Blog Entries
    4
    Quote Originally Posted by Moonfall View Post
    #define I_AM_NOT_A_STRING "666"

    Maybe?
    correct ka hehehe sayop man diay ako question

    sige ako iupdate ang question

    [Question]
    given the following macro definitions, I want to create a new macro named VERSION. This VERSION macro should be equal to "1.0.2" where the 1, 0 and 2 are the variables defined by MAJOR_V, MINOR_V and REVISION_V respectively.
    Code:
    #define MAJOR_V 1
    #define MINOR_V 0
    #define REVISION_V 2
    
    //#define VERSION //how can I combine the above 3 to form a string of the format "MAJOR_V.MINOR_V.REVISION_V"
    no hardcoding of values should be done

  6. #26
    w00t! post pa mo og daghan guys! Maka engganyo ni og programming da.

  7. #27
    #define MAJOR_V 1
    #define MINOR_V 0
    #define REVISION_V 2
    #define VERSION MAJOR_V.MINOR_V.REVISION_V <- idk if it works and I don't know how to convert it into a string?
    (Probably, Wrapper Classes?) haha

  8. #28
    #include <stdio.h>
    #define MAJOR_V "1"
    #define MINOR_V "0"
    #define REVISION_V "2"
    #define VERSION MAJOR_V "." MINOR_V "." REVISION_V

    int main()
    {
    printf("%s",VERSION);
    return 0;
    }

    naka ahat kog quickie code sa codepad.org

  9. #29
    #include <stdio.h>
    #define STRINGIFY(A) #A
    #define STR(A) STRINGIFY(A)
    #define MAJOR_V 1
    #define MINOR_V 0
    #define REVISION_V 2
    #define VERSION STR(MAJOR_V) "." STR(MINOR_V) "." STR(REVISION_V)

    int main()
    {
    printf("%s",VERSION);
    return 0;
    }

  10. #30
    C.I.A. Sarevok's Avatar
    Join Date
    Apr 2007
    Gender
    Male
    Posts
    2,802
    Blog Entries
    4
    Quote Originally Posted by KeYmAkEr View Post
    #include <stdio.h>
    #define STRINGIFY(A) #A
    #define STR(A) STRINGIFY(A)
    #define MAJOR_V 1
    #define MINOR_V 0
    #define REVISION_V 2
    #define VERSION STR(MAJOR_V) "." STR(MINOR_V) "." STR(REVISION_V)

    int main()
    {
    printf("%s",VERSION);
    return 0;
    }
    ^ win

    ang trick kay expanding macro definitions

  11.    Advertisement

Page 3 of 6 FirstFirst 12345 ... LastLast

Similar Threads

 
  1. what is your favorite programming language?
    By sachem in forum Programming
    Replies: 310
    Last Post: 10-08-2015, 03:11 PM
  2. Python programming questions
    By Louis in forum Programming
    Replies: 8
    Last Post: 09-10-2014, 10:51 AM
  3. Beware of 'tricked out' Hijack program
    By cliff_drew in forum Software & Games (Old)
    Replies: 4
    Last Post: 06-24-2009, 02:38 PM
  4. Boot using USB w/ different programs (question)
    By babolgam in forum Computer Hardware
    Replies: 5
    Last Post: 01-22-2009, 11:17 AM
  5. question on networking programming
    By poymode in forum Programming
    Replies: 6
    Last Post: 12-29-2008, 08:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top