Good Day,

As u can see I have been away from programming for a while and I have a task that desperately needs me finsh a program. I am trying to use the rename(arg1,arg2),feature of c to rename files on the system. Since the path to these files are long I need to be able to concatenate a few char arg[] into one char arg[]. It is not working though!! Any tips?


Muthu

PS: here is sort of what I did - I am not sure how to make the formula workat the rename line, I know that the str+blah blah... doesnt work, but I am not sure what will, I tried so many variations.

int main()
{
int result;
for (int counter = 101;counter<=450;counter++)
{
char str1[] = "C:/";
char str2[] = "ABC/bbb/testing";
result = rename(str1+str2+counter+".txt","C:/newfolder/newfile.txt")
)
}

you can't contantinate C style character arrays like that. Create a third buffer that is _MAX_PATH bytes long (if you are using MS-Windows os, I don't know what it is on *nix), then use sprintf() to create the string. Remember the format string uses "%s" for strings and "%d" for integers. so if you are formatting a string that will contain another string and an integer, the format specifier for sprintf() will be "%s%d".

Acient Dragon,

Thanks for the advice. It worked great. I didnt realize that function was even available. I had a difficult time figuring our and using the function but it worked.!! Thanks.

Muthu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.