I am coding for a rar password cracker. I am reading the password from a file and passing it to sprintf function. This is the code.
FILE* fp = fopen("password.txt","r");
while ( fgets ( pword, sizeof(pword), fp ) != NULL )
{
sprintf(command, "rar e -p%s realp.rar", pword);
printf(command);
//system(command);
}
This code looks fine but it's not working. Therefore I commented the system fubction and printing the variable "command". The output is like this :
rar e -pfirstpassword
realp.rarrar e -psecondpassword
realp.rarrar e -pthirdpassword
realp.rarrar e -pfourthpassword realp.rar
I can see it's breaking.The output should come like this.
rar e -pfirstpassword realp.rar
rar e -psecondpassword realp.rar
rar e -pthirdpassword realp.rar
rar e -pfourthpassword realp.rar
can anybody help me to solve this? Thanks in advance.
- operating system : windows 7
- compiler : dev c++