klimi
Mat
Welcome!
MᏫᎻᎯᎷᎷᎬᎠ
元
Okai
MᏫᎻᎯᎷᎷᎬᎠ
If not
Mat
BUT that message up there is enough
MᏫᎻᎯᎷᎷᎬᎠ
I would sing a song in Arabic🤣
Vincenzo
hello, could someone explain me what i am doing wrong?
'''#include <new>
uint8_t *pArray;
void setup()
{
pArray = new (std::nothrow) uint8_t[100];
if (pArray == nullptr)
{
//error
}
//delete[] pArray;
}
void loop()
{
add();
print();
delay(5000);
}
int8_t add()
{
uint8_t size = random(50, 99);
for (uint8_t n = 0; n < size; n++)
{
uint8_t number = random(0, 255);
*pArray++ = number;
}
return 1;
}
int8_t print()
{
for (uint8_t n = 0; n < 100; n++)
{
//*pArray++
}
return 1;
}'''
Vincenzo
Mat
At least format it as code
Mat
And tell us about the error
Mat
Runtime error? Compile error? Which one?
Mat
Have you read pinned message?
klimi
klimi
He haven't been rude
klimi
Ye
Mat
He even can spread the word about it
klimi
klimi
We are not that cruel
Mat
Please @aster94ct, do a proper question :)
klimi
GN buddy
Mat
GN @KlimiCZ
klimi
Ty ty
Vincenzo
klimi
I Will do some research to know when I should wake up
MᏫᎻᎯᎷᎷᎬᎠ
Guys GN
Mat
klimi
Hmmmm
klimi
It's nice tho to have this data
Vincenzo
so I am having some trouble with pointers, i would like to fill an array (with random data) and then print that array
#include <new>
uint8_t *pArray;
int main(void)
{
pArray = new (std::nothrow) uint8_t[100];
if (pArray == nullptr)
{
//error
}
uint8_t size = random(50, 99);
for (uint8_t n = 0; n < size; n++)
{
uint8_t number = random(0, 255);
*pArray++ = number;
}
for (uint8_t n = 0; n < 100; n++)
{
//*pArray++
}
//delete[] pArray;
}
Vincenzo
the problem is that i can't fill the array and so i can't also print it
Mat
Why you're using *pArray++ instead of pArray[n]?
Mat
What's the error?
Mat
It gives you something or you arrive at the end with just a blank array?
Vincenzo
Mat
Vincenzo
^
because it was the mistake i was looking for 😂
Vincenzo
#include <iostream>
#include <new>
uint8_t *pArray;
int main(void)
{
pArray = new (std::nothrow) uint8_t[100];
if (pArray == nullptr)
{
//error
}
uint8_t size = 60;
for (uint8_t n = 0; n < size; n++)
{
uint8_t number = 98;
pArray[n] = number;
}
std::cout << "print\n";
for (uint8_t n = 0; n < size; n++)
{
std::cout << *pArray;
}
//delete[] pArray;
}
Vincenzo
thanks!
Mat
Filled with 0s?
Vincenzo
anyway now it works
Mat
First, using ++ overwrite the variable. You shouldn't (and i remembered you couldn't) use ++ with an array pointer
Mat
If a points to the head of an array, a++ will be equal to a = a + 1, thus losing where the head of the array is
Mat
I'd suggest you to try something like *(pArray + n)
Vincenzo
Vincenzo
#include <iostream>
#include <new>
uint8_t *pArray;
int main(void)
{
pArray = new (std::nothrow) uint8_t[100];
if (pArray == nullptr)
{
//error
}
uint8_t size = 60;
for (uint8_t n = 0; n < size; n++)
{
uint8_t number = n;
pArray[n] = number;
}
std::cout << "print\n";
for (uint8_t n = 0; n < size; n++)
{
std::cout << *(pArray+n);
}
//delete[] pArray;
}should be correct
Mat
Now make it efficient
Vincenzo
Mat
Using only a loop
Mat
You can even jump the array part, but i don't think it is the aim here
Vincenzo
Using only a loop
ahhh yes i know how to do everything inside a for but yes it's not the aim!
Mat
Okay :)
Mat
Good luck!
Anonymous
What is the difference in
Char *string =
Char string [] =
Anonymous
I know upper one is pointer
And other is array
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
reading all the things u guys talking about making me scared like hell..can i make it possible to learn all those things in 3 years?😂
Mat
Mat
You only need patience, will and practice
klimi
Anonymous
pray for me😢
Ludovic 'Archivist'
Ludovic 'Archivist'
klimi
hi ludo
Ludovic 'Archivist'
olli
What is the difference in
Char *string =
Char string [] =
Since you have already written the assignment operator, I assume you're primarily interested in the following
void foo() {
char *p = "Hi"; // const char* in C++
char ar[] = "World";
}
as @Just1nC already mentioned
p points to the read only string literal. The string cannot/shall not be modified. Only the size of a pointer is reserved for p.
ar is an array and reserves memory depending on the value assigned. The whole string is copied into this memory location. You may modify the content of ar as you please.
ISO C++ forbids assigning a string literal to a non-const char pointer, instead you would need to write
const char * ptr = "Hello World";
They behave the same when they are function parameters e.g.
void foo(char ar[]) {}
void bar(char * p) {}
Anonymous
Dima
what would one prefer:
serialize simple int32 in data OR serialize header byte for uint8/16/32 and then read value by its size?
Mr. M
Looking for someone who can help me programm a bot that works with SocialMedia. PM if interested and I can also pay you a little bit 😊
klimi
hmmmmmm
klimi
klimi
usually we discuss the programming or some problems here