السلام عليكــم ورحمـة الله وبركاتــه
i have some problem with this code because i need to rename files show how to execute myprog.c in the terminal:
root@$: ./ myprog.c a.txt b.txt
but b.txt already exists, myprog.c will move the file to b.txt.1. Note that if b.txt.1 exists, you
must rename the file to b.txt.2, and so on, until you can successfully rename the file to a name
that does not already exist.
#include<string.h>
#include<stdio.h>
int main(int argc,char *argv[])
{
int i=1;
int result;
if ( argc = 2 ){
while ( argv[2] != NULL ){
i++;
result= rename( argv[1] ,strcat(argv[2],".i")); // i can not count number of file , just print i after file name like b.txt.i
break;
}
}
if ( result == 0 )
puts ( "File successfully renamed" );
else {
perror( "Error renaming file" );
return 0;
}
else
printf("ERROR IN NUMBER OF ARGUMENTS \n");
}شكراً
