I would like to write a program in C that can rename a number of files under MS Win 7 environment (NTFS file system). Hence the rename()
function seems to be a natural choice. However, when I write the following in Dev-C++ (but naming the source file as .c):
rename(name1, name2);
Compiling the file gives me the error:
[Error] called object 'rename' is not a function
I have already added <stdio.h>
as the header. Is there anything I am missing?
The source code is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 50
#define MAX 49
int main()
{
int *p;
int i, rename;
char name1[25], name2[25];
srand(time(NULL));
rename = 0;
p = (int *)malloc(sizeof(int) * N);
for (i = 0; i < N; i++)
p[i] = 0;
for (i = 0; i < MAX; i++) {
if (p[i] == 0) {
printf ("** ", i);
sprintf(name1, "abc%d.jpg", i);
sprintf(name2, "abct.jpg");
rename(name1, name2);
}
}
return 0;
}
I think you have some variables named with rename
, that's why compiler gives called object 'rename' is not a function
. Check this one. As said in the comment, please give more about your code.