Anonymous
Just returning is not
Serenity
Why's that ?
Anonymous
Try googling
Sasuke
I copied a character array to dynamic array
Sasuke
Character by character like DynamicArary[x][y] = fixedArray[z]
Sasuke
However I haven't copied '\0' character
Sasuke
But I can easily iterate through dynamic array with index
Sasuke
Why? I expect error here because how does C know where to stop?
Alex
show code how do you iterate. and how you declare array
Sasuke
Iteration is on line 32 rest copying and allocation are commented
Alex
for (int i = 0; i < numberOfStrings; i++) { printf("%s\n", command[i]); } you just traverse command[0], command[1] etc until i < numberOfStrings. you don`t need \0 for this
Sasuke
but why C finds out when first element end by \o character
Sasuke
since strings are just character sticked together
Alex
but why C finds out when first element end by \o character
cause stdlib does not use variable for string length(numberOfStrings), it traverses string until \0 is reached
Sasuke
Alex
what do you mean C? what function do you use?
Alex
In C you can use \0(standard approach) or can use just variable for string length
Alex
in the second case stdlib is not for you
Sasuke
what do you mean C? what function do you use?
C the programing language ofcourse
Sasuke
In C you can use \0(standard approach) or can use just variable for string length
So In case of variable I don't have to tell when particular element ends (by \0)
Alex
if you have string usually you have to add \0 to the end of string
Alex
if you have array you don`t have to add \0
Sasuke
if you have array you don`t have to add \0
I have array or strings as you saw
Alex
I have array or strings as you saw
to each string of this array you have to add \0. to the array itself you should not add \0
Sasuke
to each string of this array you have to add \0. to the array itself you should not add \0
Yes but I didn't add \0 for each string as you can see in line 93 I just skipped over it and I still can iterate without any issue
Alex
it is UB in this case. no guarantee it will work on other hardware in the future
Alex
printf("%s\n", command[i]);
Alex
for printf(%s function call command[i] must be ended with \0, so you should
Alex
and you should allocate +1 byte for each string for \0 byte
Sasuke
I added \0 in the end
Sasuke
Now
Sasuke
Thankyou
Alex
welcome
Manuel
Done
Dima
/ban @meak666
Hermann
where can I find good programming rules about C? I mean how to formally write the code, avoid using the variables incorrectly: such as understanding how to manage global variables and when to use them etc ...
Hermann
sorry me, i talk about C
PO
I need help
PO
I get segmentation fault (core dumped), while I write my whole function into new_file.c
PO
post in pastebin and share here
How should I do that? I've never pastebin something
Hermann
I don't get along with the French
olli
How should I do that? I've never pastebin something
https://paste.ubuntu.com/ paste your code here and share the link
PO
https://paste.ubuntu.com/p/rTWkTsxsQJ/
PO
https://paste.ubuntu.com/p/rTWkTsxsQJ/
when I want call this function with g_signal like that I get segmenation fault (Core Dumped)
PO
g_signal_connect(G_OBJECT(charge_image_bouton), "clicked", G_CALLBACK(check), (addition *) p );
Anonymous
sorry me, i talk about C
There's good book called Modern C AFAIK it's free for every one But my advice is to stop writing C, it's not a language for good code
PO
Why don't you use Qt?
Because it's a project for university, My teacher ask me to use gtk
Anonymous
F
klimi
F
My uni starts soon xD
Indolent
What exactly does "string("")" keyword does in: "accumulate(sample.begin(), sample.end(), string(""))";
Indolent
Where sample is: vector<string> sample;
Indolent
So it turns out that it adds a string "" at the beginning of the sample vector.
Cengizhan
Where sample is: vector<string> sample;
Example: sample = {“Hello”, “world”}; After function call output will be Helloworld
Cengizhan
Concatenate strings without any characters. If last parameter was string(“ “), my example would be “Hello world”
Indolent
Can you do some alteration with the first two parameters namely: sample.begin(), sample.end() ?
Indolent
Like what if instead at the beginning I want to add in the middle of the string?
Anonymous
C++ Core Guidelines
these are new library?
Đỗ
no, it's only a cookbook
Indolent
i = i == 1 ? 0 : 1;
Indolent
What is the meaning of the above line?
Cengizhan
What is the meaning of the above line?
If i is 1, make it 0 otherwise make it 1.
Indolent
Then why i = at the beginning?
Indolent
Why not just i == 1 ? 0 : 1
Cengizhan
Why not just i == 1 ? 0 : 1
There is no assignment operator here.
Indolent
oh fuck
Cengizhan
Thats why we keep equal sign first there.
Indolent
omg why didn't i thought of that
Indolent
we're simply assigning the value of i
Indolent
No Kardarshians here