Anonymous
Source code:
/* cp command simulation - copy.c */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#define SIZE 1024
int main(int argc, char *argv[]){
int src, dst, nread;
char buf[SIZE];
if (argc != 3){
printf("Usage: gcc copy.c -o copy\n");
printf("Usage: ./copy <filename> <newfile> \n");
exit(-1);
}
if ((src = open(argv[1], O_RDONLY)) == -1) {
perror(argv[1]);
exit(-1);
}
if ((dst = creat(argv[2], 0644)) == -1){
perror(argv[1]);
exit(-1);
}
while ((nread = read(src, buf, SIZE)) > 0){
if (write(dst, buf, nread) == -1){
printf("can't write\n");
exit(-1);
}
}
close(src);
close(dst);
return 1;
}
Anonymous
nvm, I found it,
looks like read(), write() declarations are in #include <unistd.h>
But I wonder How it worked for the gcc MINGW in my windows
Богдан
This maybe help u
"main.c: In function ‘main’:
main.c:25:18: warning: implicit declaration of function ‘read’; did you mean ‘fread’? [-Wimplicit-function-declaration]
25 | while ((nread = read(src, buf, SIZE)) > 0){
| ^~~~
| fread
main.c:26:9: warning: implicit declaration of function ‘write’; did you mean ‘fwrite’? [-Wimplicit-function-declaration]
26 | if (write(dst, buf, nread) == -1){
| ^
| fwrite
main.c:31:2: warning: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Wimplicit-function-declaration]
31 | close(src);
| ^
| pclose"
Anonymous
Anonymous
/get
MAC
Lol
armandofsanchez
armandofsanchez
So its pointing to the next position
armandofsanchez
Of memory
Gulshan
https://del.dog/egrestarod.txt
Gulshan
Gulshan
what should be done ?
Gulshan
Gulshan
Ishank
Hlo i need some likes on insta photo , can i send here?
Gulshan
but this actually reduces some time
Nils
Send in PM instead, or #off-topic at least
a Semicolon
Nils
Ishank
Serhat
hi, how can i store integers without using array?
Serhat
Prince Of Persia
Serhat
Ammar
Prince Of Persia
C :(
Use pointers with malloc()
Ammar
Without array, you can use linked list anyway.
Serhat
Ammar
Serhat
Jomac d Learner
Please i need a good c++ programmer to inbox me for a project
Thanks
klimi
Ahadu
Nameful
Ahadu
grew hat hacker
They are hackers sometimes like white hat hacker sometimes Black hat hackers
AS🌸
Could any one help with this https://github.com/AndyNovo/speedruns/commit/fa54d698b7bb5cee0d133b63d9495541860c0d28#diff-914798cf605097c01d7649b09273a50d142cc7c26abf76054f727a7d596571f5
Ahadu
How many hackers are there
Diego
Dima
Anonymous
klimi
Юрій
There are two types, white and those who were caught)
AmR
Any one know where I can find src for file command ?
Ammar
What's the deal in comparing malloc and bzero?
They both serve different purpose.
Vlad
Lol they function differently
Nomid Íkorni-Sciurus
I'm new to this. What is bzero?
Vlad
"cup or the pencil"
Vlad
MAC
Nomid Íkorni-Sciurus
Ammar
Vlad
Nomid Íkorni-Sciurus
Vlad
memset exists for that
Vlad
Nomid Íkorni-Sciurus
yeah
MAC
I use t9
MAC
Vlad
Why don't?
It copies from one memory location to the other. It doesn't fill memory uniformly
Vlad
So you'd need an array of exact size full of zeros to zero fill this one
Vlad
Which just defies the purpose
Vlad
AmR
Vlad
And it must be the same size or more
MAC
Vlad
Lmao
MAC
MAC