4 hours spent cant figure out why its shrinking its size.
#include <avr/pgmspace.h>
#include <stdio.h>
#include <stdlib.h>
void check_internet(const char destination[]);
void ping_module(const byte module);
#define ip_address_size 16
const char M_IP[] PROGMEM="192.168.4.";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
ping_module(5);
delay(2000);
// put your main code here, to run repeatedly:
}
void ping_module(const byte module) {
const byte base = 10;
if (!module) return;
char _buffer[3];
memset(_buffer, '\0', sizeof(_buffer));
char module_ip_temp[ip_address_size];
memset(module_ip_temp, '\0', sizeof(module_ip_temp));
itoa(module, _buffer, base);
for (byte i = 0; i < strlen_P(M_IP); i++) module_ip_temp[i] = pgm_read_byte_near(M_IP + i);
strcat(module_ip_temp, _buffer);
char module_ip[strlen(module_ip_temp) + 1];
memset(module_ip, '\0', sizeof(module_ip));
strcpy(module_ip, module_ip_temp);
Serial.print(F("strlen of module_ip="));
Serial.println(strlen(module_ip));
for(byte i=0;i<strlen(module_ip);i++){
Serial.print(module_ip[i]);
Serial.print('\t');
Serial.println(i);
}
Serial.print(F("size of destination before calling function"));
Serial.println((unsigned int)(sizeof(module_ip)/sizeof(module_ip[0])));
check_internet(module_ip);
return;
}
void check_internet(const char destination[]) {
Serial.print(F("size of destination in function="));
Serial.println((unsigned int)(sizeof(destination)/(sizeof(destination[0]))));
return ;
}
output:
strlen of module_ip=11
1 0
9 1
2 2
. 3
1 4
6 5
8 6
. 7
4 8
. 9
5 10
size of destination before calling function12
size of destination in function=2
thanks