Pavel
Ok
I've just checked. It does support c++17
Pavel
You have to modify compiler options in the app Settings
Pavel
It's set to c++14 by default
AHMED
It's set to c++14 by default
Yes, you are right. I modified it and it worked. Thank u 💐💐
Anonymous
Which do you use Using namespace std Or Std::cout I ask because I read that using namespace Std has some problems
Pavel
Which do you use Using namespace std Or Std::cout I ask because I read that using namespace Std has some problems
Second in real code, first in code examples (e.g. in presentations or to past here)
Vlad
using namespace std; is fine if you use it locally
But please don't put it in the header files. It is mortal sin
Bumpy
int length = lengthOf(string); char *sorted = (char*)(calloc(length + 1,sizeof(char))); while (*string) { *sorted = *string; sorted ++; string ++; }
Bumpy
anyone know why its doesnt copy?
Bumpy
?
Bumpy
im implement that
Bumpy
with strlen its doesnt work also
Pavel
int length = lengthOf(string); char *sorted = (char*)(calloc(length + 1,sizeof(char))); while (*string) { *sorted = *string; sorted ++; string ++; }
Why do you prefer copying strings symbol by symbol? Why not use memcpy? Also, have you checked that length is correct?
Igor🇺🇦
int length = lengthOf(string); char *sorted = (char*)(calloc(length + 1,sizeof(char))); while (*string) { *sorted = *string; sorted ++; string ++; }
Where do you want to copy it to? How do you check that it's copied? How do you calculate beginning of the "sorted" since you're not storing it anywhere.
Aakash
int length = lengthOf(string); char *sorted = (char*)(calloc(length + 1,sizeof(char))); while (*string) { *sorted = *string; sorted ++; string ++; }
int main() { char *string = "Hello!Baby"; int length = strlen(string); char *sorted = (char*)calloc(length, sizeof(char)); //this-is-storage: sorted[length]; //this-is-pointer: *sorted; int i=0; while ((sorted[i] = *string) != '\0') { i++; string++; } printf("\nString: %s", sorted); } 🙃
Igor🇺🇦
Why if strcpy exists?
Prefer strncpy. It is safer.
Aakash
I think your code has one off by 1 error. You need to calloc length + 1.
int main() { char *string = "Hello!Baby"; int length = strlen(string); char *sorted = (char*)calloc(length, sizeof(char)); int i=0; while (*string != '\0') { sorted[i++] = *string; string++; } printf("\nString: %s", sorted); printf("\n"); while (*sorted != '\0') { printf("\nSorted: %s", sorted); sorted++; } } How?🙃
Vlad
It has to be placed manually
Tekipeps
hello
Tekipeps
im having segfault while trying to set data https://pastebin.com/nbW1jJPh
Anonymous
I have to display a menu How do u want to forcast your list? 1. All Items 2. By Priority 0. Quit How do i do this .
Pat
Hi everyone
Anonymous
Mambos
Anonymous
I use fmt::print 😜
Which module did you inculde to get that syntax
Pavel
You will have a function declaration then, not sure what you mean? What happens with what?
Pavel
You mean what type of the argument should be?
Pavel
Is it C or C++?
Pavel
I'm not a C programmer but I believe you have three possible variants: To copy it float foo(Complex Complex); To have a pointer to it, to be able to change it in the function float foo(Complex* Complex); To have a pointer to it, not to be able to change it (just as optimization) float foo(const Complex* Complex); UPD: fixed the third case
Igor🇺🇦
Golang!
No, https://fmt.dev/latest/index.html
Pavel
For this one the first two should be fine. since it small enough, no need to try to optimize it by using pointer
Igor🇺🇦
Which module did you inculde to get that syntax
I didn't understand the question.
Vlad
Did you mean const Complex*?
Pavel
Did you mean const Complex*?
Yes! Thanks (Fixed)
Igor🇺🇦
I didn't understand what you mean by "syntactically understand what happens". With this syntax you copy values a and b into foo and use copies inside. By the way, there is a support for complex numbers in C99 https://en.cppreference.com/w/c/numeric/complex
Igor🇺🇦
What? What file scope? Your explanation didn't help. At least me 🤷‍♂️
Aakash
typedef struct Complex { float real; float imag; } complex; float foo(complex cx) { ...🙃... }
Anonymous
can i take index 1 in array ,thus gcc allow me?
Anonymous
instard of index 0
Aakash
..Also try to avoid complex name, as there is header file complex.h which uses type “complex” for complex math..
Igor🇺🇦
What is file scope?
Asad
There is no file scope in C\C++, right? At least not without C++20 modules?
Pavel
There is no file scope in C\C++, right? At least not without C++20 modules?
No, there are translation units that can be used for the same aim (if you declare static variable/function in *.cpp) but that's more a convention, not a standard C++ thing.
Asad
So, modules will solve this?
S__R
can a function in c return 2 values
Asad
No. You can use a struct with two fields or pass pointers.
S__R
No. You can use a struct with two fields or pass pointers.
one more sturucture in program😅😅😅😅
Asad
Yes. Something like std::pair
S__R
pass pointers is easy
Anonymous
Bumpy
int main (){ const char* const ptr[3]= {"Ariel","University","BANGKOK"}; char *s; (&s)[3] = "a"; ptr[2] = "b"; for (int i = 0; i < 3; i++) { printf("%s\n",*(ptr + i)); } return 0; }
Igor🇺🇦
Why you say Fmt::print
The question was what do you use cout or std::cout. I prefer using fmt::print it has much nicer syntax and is faster
Bumpy
anyone know why i can change the value of ptr[2] by using (&s)[3] ?
Asad
s is uninitialized.
Bumpy
s is uninitialized.
int main (){ const char* const ptr[3]= {"Ariel","University","BANGKOK"}; char *s ="hey"; (&s)[3] = "a"; ptr[2] = "b"; for (int i = 0; i < 3; i++) { printf("%s\n",*(ptr + i)); } return 0; }
Bumpy
its same on the comile
Bumpy
compile
Bumpy
no.. its working
Vlad
Rockets were fired on russia
Bumpy
vlad u know why its working?
Vlad
no.. its working
Undefined behavior
Vlad
It does not "work"
Vlad
Even if you think it does
Bumpy
but who? the array is constant and thats means that all vairable are read onky
Bumpy
how?*