Anonymous
To be honest, I only use GitHub to store my tiny projects that I don't want to lose in an imminent format
Anonymous
E.g. change Linux distro
Anonymous
Or format Windows
Mat
Help me to solve this doubt
Only the pointer should be const in that case
BinaryByter
Help me to solve this doubt
const char not char const, also STOP ABUSING POINTERS, also main has got to have a return type, also you cant define two variables that get a value at once, also dafaq is line 6?
BinaryByter
It's a strange program🤣🤣🤣
I think that someone opened an antique book on page 800 and thought to themselves "programming === maths, it won't be too hard lets dive into this"
BinaryByter
TIL
Kalpesh
the compiler is not generating eny error on that program?
Yes that is tha the issue.. compiler not getting any error.
Kalpesh
But actually const *p value doesn't change so why we used??
BinaryByter
thats probably some weirdness of C in regards to pointers
Anonymous
+1 Gitlab let you have both private and public repos
I can't stand Gitlab for some reason
Anonymous
Probably because it is the shelter for GitHub emigrants
Anonymous
Which actually has no sense since a programmer should not bother about a company being sold
BinaryByter
I share your opinion
Mat
I prefer open source products not owned by a big company
BinaryByter
github has never been FOSS
Mat
I know :)
Артём
Hello everyone, could you help me please. I'm trying to execute an existing program rec and pass array of strings arr as an argument. All works as needed, but not always: when I enter only '\n', the execv returns -1 and error 14 Bad address. int main(int argc, char ** argv) { vector<string> vMessage; char ch; string tmps; while (ch != '\n') { ch = getchar(); if (((ch == ' ') || (ch == '\n')) && (tmps != "")) { vMessage.push_back(tmps); tmps = ""; } else tmps += ch; } char * arr[] = {"QWE11", "Asd22"}; cerr << endl << execv("rec", arr) << endl; perror(""); } I have no idea, how variables ch, vMessage, tmps are related to the function execv with array arr I initialized in my code. Why does thic error occur only in that case?
BinaryByter
user std::string
BinaryByter
in general, STOP USING POINTERS
BinaryByter
a wait
BinaryByter
this is a main function
BinaryByter
Check wether the inputted adress is empty or not
Артём
user std::string
int execv(const char*, char* const*) . 1) I need to pass array of strings. 2) function execv requires char* const* as second argument.
BinaryByter
char* const*
BinaryByter
are you sure about that?
Артём
Yes.
BinaryByter
are you sure that it isnt char* const?
BinaryByter
anyway, what is this second argument doing?
Артём
are you sure that it isnt char* const?
Yes, I'm totally sure. Second argument isn't a string, it's an array of char* .
BinaryByter
I hate libraries that use shitty syntax
Артём
anyway, what is this second argument doing?
Do you know exec... ? If it is execv, the second argument is an array of char*, which will be passed to program being executed(first argument).
BinaryByter
Oh I see
BinaryByter
we are talking about piping
BinaryByter
Except the entire loop is useless since you are hardcoding the values
Артём
I didn't understand. How is this loop related to execv?
BinaryByter
Exactly, it isnt
BinaryByter
Thus it's useless
BinaryByter
you could as well throw it out
BinaryByter
How so?
Артём
If I enter nothing, just press the key "Enter", input '\n', then the execv returns -1 and error 14 Bad address.
BinaryByter
and if you input something else?
Артём
Otherwise, any another input doesn't make the loop influence the function execv .
BinaryByter
Im afraid i cant help ya
BinaryByter
What are your includes?
BinaryByter
I feel like you use a fucked up library
Артём
What are your includes?
#include <cstring> #include <iostream> #include <stdlib.h> #include <vector> #include <unistd.h> #include <errno.h> But they aren't related to the problem, the code gets compiled successfuly.
BinaryByter
Okay so stdlib
Anonymous
Artyom esli ne poluchayetsa poluchit normalno stroki tupo zapisivay ih v fayl
Anonymous
Vsegda tak delayu
Артём
I know this way.) But I have another problem: the loop influences the funtion it's not related to anyway.
Anonymous
Hmm
olli
I know this way.) But I have another problem: the loop influences the funtion it's not related to anyway.
"The list of arguments must be terminated by a null pointer, and, since these are variadic functions, this pointer must be cast (char *) NULL." (source: man execv)
Артём
olli
such as char * arr[] = {"QWE11", "Asd22", (char*)0};
olli
#include <unistd.h> #include <errno.h> int main(int argc, char ** argv) { char * arr[] = {"", "Hi there", "Asd22", (char*)0}; execv("/bin/echo", arr); }> Hi there Asd22
BinaryByter
use std::vector with std::vector::data()
BinaryByter
should be more modern
olli
My Example is C, therefore errno.h instead of cerrno
BinaryByter
ewww
BinaryByter
lol