Volad Malevich
@veficos how?😊
veficos
void gettime(char* buffer){ struct timeval time_now; char ms[7]; gettimeofday(&time_now, NULL); struct tm *time_str_tm = gmtime(&time_now.tv_sec); strftime (buffer, 256, "%d.%m.%Y %H:%m:%S", time_str_tm); sprintf(ms, ":%06ld", time_now.tv_usec); strcat(buffer, ms); }
Volad Malevich
@veficos In function ‘gettime’: ./bin/start.c:10:5: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration] gettimeofday(&time_now, NULL);
veficos
#include <time.h> #include <sys/time.h>
Volad Malevich
works great!!! Thanks a lot guys @veficos @vbextreme @ssynx 👍😊
Anonymous
No need a free
VbExTreMeEEEEeEEeeeeE
veficos
Check the features test macros...
Many glibc are supported, no matter....
Anonymous
Many glibc are supported, no matter....
Yes _BSD_SOURCE required for settimeofday
Nazir
Hi
Volad Malevich
help again pls)
Volad Malevich
i need to get result of system("ps -A") to variable
Volad Malevich
is it possible?
klimi
Hi
Hi
veficos
u can use pipe to receive result..
Joe
please help. I included a header file in my project and everything compiles without a problem, but when using the functions from the header file it says undefined reference to (function)
Volad Malevich
please help me to get result of system("ps -A") to variable via PIPE or other way. I found some in google, but it's not exactly what i need.
Volad Malevich
?
veficos
like: int pid; int fds[2]; pipe(fds); pid = fork(); if(pid == 0){ close(1); dup2(fds[1], 1); close(fds[0]); execlp("ps", "ps", "-a", NULL); } else { char buffer[8192*16] = {0}; while (1) { char buf[1024]; int n = read(fds[0], buf, 1024); if (n <= 0) { break; } memcpy(buffer, buf, n); if (n != 1024) { break; } } printf("%s\n", buffer); }
Volad Malevich
how to make a function with return output to buffer?
Volad Malevich
void output(char *buffer) ?
veficos
that's ok
Volad Malevich
return what?
veficos
void output(char *buffer) { int pid; int fds[2]; pipe(fds); pid = fork(); if(pid == 0){ close(1); dup2(fds[1], 1); close(fds[0]); execlp("ps", "ps", "-a", NULL); } else { while (1) { char buf[1024]; int n = read(fds[0], buf, 1024); if (n <= 0) { break; } memcpy(buffer, buf, n); if (n != 1024) { break; } } } } ... char buffer[8192*16] = {0}; output(buffer);
Volad Malevich
is execlp fits to do it?
Volad Malevich
for example "ps -A -o args | grep stop | grep 1765"
Anonymous
return what?
You may return exit value if you want
Anonymous
(Exit value of the child process)
veficos
system() instead of execlp()
Volad Malevich
)) i need this one
Volad Malevich
var = output("system command");
Volad Malevich
i need this one, where output is a void output() function
Volad Malevich
veficos
void output(char* command, char *buffer) { int pid; int fds[2]; pipe(fds); pid = fork(); if(pid == 0){ close(1); dup2(fds[1], 1); close(fds[0]); system(command); } else { while (1) { char buf[1024]; int n = read(fds[0], buf, 1024); if (n <= 0) { break; } memcpy(buffer, buf, n); if (n != 1024) { break; } } } } ... char buffer[8192*16] = {0}; output("ps aux", buffer);
Shalom
,
Anonymous
Thanks
klimi
Welcome
Thespartann
That's only one
klimi
2 to write
Marie
Felix has 1/3 warnings... watch out! Reason for last warn: advertisement
Anonymous
Yeah sure!
Morgan
Doing my assignment👌🔥🔥
Ибраги́м
BinaryByter
Dev C++
BinaryByter
no, C-Free
Mihail
BinaryByter
Doing my assignment👌🔥🔥
nothing that i'd be proud of, tbh
Mihail
Says it in the top bar of the window
Mr. COwO2 Preis
> windows
BinaryByter
> windows
windows ten, to make the matters worse
BinaryByter
using a windows XP theme
BinaryByter
xD
BinaryByter
using C unironically
Ибраги́м
C-Free 4.0
CodeLite QtCreator CodeBlocks ?
BinaryByter
C-Free 4.0
Zero
Can Anybody Teach me Linked Lists...how they work?
Zero
After declaring Struct node...i dont understood anything
BinaryByter
Can Anybody Teach me Linked Lists...how they work?
wikipedia has got a VERY NICE explanation of them
BinaryByter
Vim
you non-practical moster
Bader
nothing that i'd be proud of, tbh
at least he's not asking for us to do it for him.... look on the bright side dude :)
Mihail
What do you guys think about him and emacs?
BinaryByter
Mihail
I'd like to learn about one of these
Mr. COwO2 Preis
try emacs or vim
Mihail
So I can program via ssh in my PC at home
Mihail
try emacs or vim
Yeah can't decide tho
Roxifλsz 🇱🇹
What do you guys think about him and emacs?
Emacs is a good OS, not that good of an editor though :^)
Mr. COwO2 Preis
try emacs or vim
*both and decide by your own
BinaryByter
Yeah can't decide tho
I wouldn't choose either of them
Mr. COwO2 Preis
But it has evil mode
the best feature of emacs
BinaryByter
vsc