Professional Documents
Culture Documents
College of Engineering
GEC225 Exercises on Storage Classes and Scope 4
4.1 Extern in C
/* Listing */
void setup()
{
int x = 5;
Serial.begin(9600);
if (x < MAXVAL) {
int temp;
temp = x * 100;
Serial.print("The lvalue for temp is: ");
Serial.println((long) &temp);
Serial.print("The rvalue for temp is: ");
Serial.println((long) temp);
}
int temp;
void loop() {}
void loop() {
while (true) {
Serial.println(MyCounter());
}
}
int MyCounter()
{
static int counter = 0;
// do some stuff...
return ++counter;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
number *= number;
Serial.println(number);
}
4.4 Extern in C
_______________
/* Listing. Short Program with Error */
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
number *= number;
Serial.println(number);
}
void setup() {
char message[] = "70.0,95,15:00";
int index;
int holdIndex = 0;
int temperature;
int humidity;
Serial.begin(9600);
/*****
This method looks for a specific character in a string
return value:
int the position in the string where found or
0 if no match
*****/
int FindCharacter(char msg[], char c)
{
int i = 0;
while (msg) {
if (msg[i] == c) {
return i;
} else {
i++;
}
}
return 0;
}