is there a better way... string constatns

This is a discussion on is there a better way... string constatns within the C Programming forums, part of the General Programming Boards category; This works, but not the way I would like. I would like to asing string costants to an array. Code: ...

  1. #1
    DIY
    Guest

    is there a better way... string constatns

    This works, but not the way I would like. I would like to asing string costants to an array.


    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    #define  M "Monday"
    #define  T "Tuesday"
    #define  W "Wednesday"
    #define TH "Thursday"
    #define  F "Friday"
    #define  S "Saturday"
    #define SU "Sunday"
    
    int main()
    {
    
        struct program
        {
            int z1 ;
            int z2 ;
        } ;
    
        program prog ;
    
        scanf("%d", &prog.z1) ;
        scanf("%d", &prog.z2) ;
    
        printf("%s\t%d\n", M, prog.z1) ;
        printf("%s\t%d\n", T, prog.z2) ;
    
    
          system("PAUSE");
          return 0;
    }
    I tryed this:
    Code:
    #define MAX 10
    #define DAY 7
    
    int main()
    {
    char week[MAX]  ;
     
    week[MAX][DAY] {"Monday",.............}  ;   /*all days of the week*/
    
    }

  2. #2
    DIY
    Guest
    I am using Dev 4.0.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char *days[] = {
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday",
    };
    
    int x;
    for( x = 0; x < 7; x++ )
        printf("%s\n", days[x] );
    Enjoy.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    DIY
    Guest
    What I want is to read the days of the week into an array. If i'm on the wrong track please point me in the right direction.

  5. #5
    DIY
    Guest
    Thanks Quzah, thats exactly what I was looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07:02 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

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