Thread: Splitting an int array into four arrays

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Splitting an int array into four arrays

    hello i am trying to convert this BASIC code to C code :

    BASIC code:it is in another language german i think LUNDI i think is monday)

    Code:
    smybol NBALARM=16' 
    const alarmTable as  byte[NBALARM*4]=('        
     DAY             HOUR    MINUTE  DURATION 
    LUNDI,         8,    30, 10,
    LUNDI,         12,  30, 10,
    LUNDI,         14,  00, 10
    )
    my c code at the moment:
    Code:
    char alarm[3][100]={
    Code:
    //  Day           hour:     minute:   seconds:
        "Monday,        8,        30,     10,",
        "Tuesday,       9,        30,     10,",
        "Wednesday,     10,       00,     14,"
        }
    ;

    note: Monday, Tuesday ,Wednesday and LUNDI are all defined above the array as ints with values like 0,1...


    at the moment my code compiles but i know that in the future if i keep my array as a char it will cause problems because i would have to split it. so i want my array to be somewhat in the form of:

    Code:
    int alarm[3][100] as byte[alarms *4] (or something)={
    //  Day           hour:     minute:   seconds:
        "Monday,        8,        30,     10,
         Tuesday,       9,        30,     10,
         Wednesday,     10,       00,     14
        };

    i know the code above probably does not compile but you get the idea.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Why not start with say
    Code:
    struct info {
        char day[10];
        int hour;
        int minute;
        int duration;
    };
    struct info alarms[] = {
        { "monday", 8, 30, 10 },
    };
    There's no point in inheriting the basic brain-damage.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    2
    thanks alot i wasnt a big fan of structs but now i am

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-01-2011, 12:38 PM
  2. Splitting An Array
    By fault in forum C Programming
    Replies: 1
    Last Post: 02-28-2011, 10:20 PM
  3. Splitting stream of bytes into block of array.
    By gravityzer0 in forum C Programming
    Replies: 7
    Last Post: 08-22-2006, 06:27 PM
  4. Splitting up a char array?
    By stillwell in forum C++ Programming
    Replies: 28
    Last Post: 10-18-2004, 11:56 AM
  5. separating line of arrays into array of arrays
    By robocop in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2001, 12:43 AM