Shop OBEX P1 Docs P2 Docs Learn Events
char s[9]; — Parallax Forums

char s[9];

Howdy,
I was working on this exercise:
http://learn.parallax.com/propeller-c-simple-circuits/seven-segment-display
and at the bottom the second code example has the line "char s[9];" and I was just wondering what's it for? I removed it and it works fine...


/*
  Seven Segment.c
  
  Display digits on a 7 segment (common cathode) LED display.
  
  http://learn.parallax.com/propeller-c-simple-circuits/seven-segment-display
*/

#include "simpletools.h"                      // Include simpletools

int n[] = {0b11100111, 0b10000100, 0b11010011,
           0b11010110, 0b10110100, 0b01110110,
           0b01110111, 0b11000100, 0b11110111,
           0b11110100};
char s[9];

int main()                                    // main function
{
  set_directions(15, 8, 0b11111111);          // P15...P8 -> output
  pause(1000);

  for (int i = 0; i < 10; ++i)
  {                                              
  set_outputs(15, 8, n[i]);             // 0 -> 7-segment display
    print("n[%d] displayed.\n", i);
  pause(1000);
  }
}

Comments

  • char s[9]; establishes a 9 element char array and is not used in the program you posted. You can remove it or the compiler most likely will when it sees that it is not used.
  • Hal Albach wrote: »
    char s[9]; establishes a 9 element char array and is not used in the program you posted. You can remove it or the compiler most likely will when it sees that it is not used.

    Thanks, do you maybe have a link of an example of when it's used?

  • I cannot even begin to guess at what Forrest Bourke had in mind with that particular array. Possibly when he was writing that particular tutorial he cut the bit patterns from another source to paste into this tutorial and just cut that extra line unintentionally. As best as I can tell, it is just an orphan assignment statement. Without the actual source file from where it came there is no way of knowing what it was for.
Sign In or Register to comment.