Created
November 25, 2016 09:34
-
-
Save daniel-dona/53e4cf136eac18129441f56d2a1225eb to your computer and use it in GitHub Desktop.
cambiar.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
int main(int argc, char *argv[]){ | |
char *pref; | |
char newn[255]; | |
int n, i; | |
if(argc < 2){ | |
return EXIT_FAILURE; | |
} | |
if(argv[1][0] != '-'){ | |
pref = "old"; | |
n = 1; | |
}else{ | |
pref = strdup(++argv[1]); | |
n = 2; | |
} | |
//printf("%s", pref); | |
while(argc > n){ | |
//printf("%s", argv[n]); | |
sprintf(newn, "%s.%s", argv[n], pref); //Por alguna razón esto no funciona | |
/* | |
//Esto es una chapuza | |
for(i=0; i < sizeof(newn); i++){ | |
newn[i] = '\0'; | |
} | |
strcat(newn, argv[n]); | |
strcat(newn, "."); | |
strcat(newn, pref); | |
//Fin de la chapuza */ | |
if(rename(argv[n], newn) != -1){ | |
printf("%s\n", newn); | |
} | |
n++; | |
//printf("%d", n); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment