Thread: to assign a double and output it

  1. #16
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    This would be the correct code. Compare this to your code.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        char *dint1 = "poi";
        char *dint2 = "ghj";
        char *dint3 = "ggg";
    
        char *array123[3] = {dint1, dint2, dint3};
    
        printf("%s\n", array123[0]);
    
      return 0;
    }
    It does not surprise me that you are trying to learn C from a painfully inadequate tutorial instead of a very thorough book!

    If you don't want to take the time to learn the language from the beginning rather than jumping into trying to write an array of pointers to char strings, then I cannot help you any further.

    Good luck!

  2. #17
    Registered User
    Join Date
    Jul 2022
    Posts
    50
    Quote Originally Posted by rstanley View Post
    This would be the correct code. Compare this to your code.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        char *dint1 = "poi";
        char *dint2 = "ghj";
        char *dint3 = "ggg";
    
        char *array123[3] = {dint1, dint2, dint3};
    
        printf("%s\n", array123[0]);
    
      return 0;
    }
    It does not surprise me that you are trying to learn C from a painfully inadequate tutorial instead of a very thorough book!

    If you don't want to take the time to learn the language from the beginning rather than jumping into trying to write an array of pointers to char strings, then I cannot help you any further.

    Good luck!
    Thanks,

    my code was the same instead of the
    Code:
    *
    =]

  3. #18
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by WaterSerpentM View Post
    Thanks,

    my code was the same instead of the
    Code:
    *
    =]
    char something; is a far cry from char *something;!!!!

    Compare the printf() on my line 11 with the comparable line in your code! NOT the same!!!

  4. #19
    Registered User
    Join Date
    Jul 2022
    Posts
    50
    Quote Originally Posted by rstanley View Post
    char something; is a far cry from char *something;!!!!

    Compare the printf() on my line 11 with the comparable line in your code! NOT the same!!!
    yup, i get the code

    Code:
        printf("%s\n", array123[0]);
        printf("%s\n", array123[1]);
        printf("%s\n", array123[2]);

  5. #20
    Registered User
    Join Date
    Jul 2022
    Posts
    50
    just practicing

    Code:
        char *char_1 = "char1";
        char *char_2 = "char2";
        char *char_3 = "char3";
    
    
        int int_1;
        int int_2;
        int int_3;
    
    
    
    
    
        char *array_1[3] = {char_1, char_2, char_3};
    
    
        printf("%s\n", array_1[0]);
        printf("%s\n", array_1[1]);
        printf("%s\n", array_1[2]);
        printf("\n");
    
    
        for(int_1 = 0; int_1 < 3; int_1++)
            printf("%s\n", array_1[int_1]);
            printf("\n");
    
    
        for(int_2 = 2; int_2 > -1; int_2--)
            printf("%s\n", array_1[int_2]);
            printf("\n");
    
        for(int_3 = 0; int_3 < 3; int_3++)
            printf("%s " "%s " "%s\n", array_1[int_3],array_1[int_3],array_1[int_3]);
    Last edited by WaterSerpentM; 10-19-2023 at 06:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cant get a double type output ??
    By hummingdev in forum C Programming
    Replies: 3
    Last Post: 04-01-2014, 04:13 PM
  2. double/float output is inaccurate.
    By slee8251 in forum C Programming
    Replies: 8
    Last Post: 03-13-2012, 01:27 AM
  3. Comma instead of period in Double output
    By trillykins in forum C Programming
    Replies: 1
    Last Post: 11-19-2010, 09:29 AM
  4. Double output!
    By Spurnout in forum C++ Programming
    Replies: 3
    Last Post: 11-02-2002, 03:35 AM
  5. Floating points and Double output
    By bman1176 in forum C++ Programming
    Replies: 2
    Last Post: 10-11-2001, 12:24 AM

Tags for this Thread