I am writing an application which has to find the sub string from a file and write this sub string into some different file. For writing into a file , I am using fputs, but someone told me to check the safer version for writing into the file.
while (fgets(line, MAX_LINE_LEN, fp1) != NULL) {
if (pname_count < 1) {
if (strstr(line, p_name)) {
pname_count++;
fputs(strstr(line, p_name), fp2);// danger.
continue;
}
}
//Remaining code
}
Followed two below links, but did not get my answer exactly.
gets() and fputs() are dangerous functions?
Can someone explain what is the vulnerability with "fputs" in terms of safety.?
Since fwrite takes the number of characters to write into the file, does this make fwrite more safer than fputs?