I have a code whose mission is to copy a source to a destination. The point is that, when compiling, it warns me that on line 38 an assignment is made from an integer to a pointer without a molding and I do not know how to fix it.
Also, running it in linux gives me a generated 'core' segment violation. Likewise, execution is aborted in CodeBlocks.
This is my code:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
int copia (char * ruta_fue, char * ruta_des){
int fd_fue,fd_des,leidos,escritos;
void * dato;
if(access(ruta_des,F_OK)==0){
fd_fue = open(ruta_des,O_WRONLY|O_TRUNC);
} else {
fd_fue = creat(ruta_des,0600);
}
fd_fue = open(ruta_fue,O_RDONLY);
if(fd_fue<0){
fprintf(stderr, "Ha fallado la apertura de %s\n", ruta_fue);
perror("");
return -1;
}
while( ( leidos = read(fd_fue,&dato,sizeof(int) ) ) > 0 ){
if( ( escritos = write(fd_des,dato,leidos) ) < 0 ){
fprintf(stderr, "Ha fallado la escritura de %s\n", ruta_des);
perror("");
return -1;
}
}
close(fd_fue);
close(fd_des);
printf("La copia se ha realizado bien");
return 1;
}
int main(int argc, char * argv[]){
char * ruta_fue,ruta_des;
ruta_fue = (char *)argv[1];
ruta_des = (char *)argv[2];
copia(ruta_fue,ruta_des);
struct stat info_fue, info_des;
stat(ruta_fue,&info_fue);
stat(ruta_des,&info_des);
if(info_fue.st_size!=info_des.st_size){
fprintf(stderr,"Los tamaños de %s y %s no coinciden",ruta_fue,ruta_des);
return -1;
}
printf("Los tamaños de %s y %s son iguales",ruta_fue,ruta_des);
}
Note: line 38 is ruta_des = (char *)argv[2];
.