char ch,s[100];
char r[100]="REN ";
...
char v[50];
You're using fixed size strings here! Your later operations, most notably
strcat
, are likely to write beyond the end of these arrays and cause undefined behaviour! Even if it works for simple tests, the later concatenations depend on the input folder name, and therefore the length of that name. Best way to avoid that would be using an actual string type, such as
std::string
.
p=fopen("D:\a.bat","w+");
As has been pointed out in the comments, '\' is an escape character, and this line, as well as the others below, are not accessing the file you think it does - in fact it will likely be the reason for your program to crash, or fail at a later point. Replace all single '\' in your filenames with double '\\'. better yet, define a string variable to hold that filename instead of constantly repeating the actual name - and then mistyping it to "C:\a.bat" like you did towards the end.
for(i=0;i<25;i++)
fputs("echo This software is not responsible for any loss in data",p);
... and later ...
for(i=0;i<25;i++)
fputs(" echo This software is not responsible for any loss in data ",p);
fputs("exit",p);
}
Did you really mean to repeat that 50 times? Or write it at all for that matter?
case 1:
...
printf("Enter new name of your folder/file");
...
case 2:
...
printf("Enter new name of your folder/file");
Not a helpful comment you print there - you might want to change them to something meaningful - or at least different.