I'm working on a portion of a program that deals with overwriting files in a directory. Overwriting the files is easy... but apparently making the prompt that asks users if they wish to overwrite the file is not. For example: if I wish to overwrite two files (fileOne.txt, fileTwo.txt), I need to prompt the user twice (once for each file). With my current prompt, if I prompt the user to overwrite fileOne.txt, both fileOne.txt and fileTwo.txt will be overwritten. If there are more than two files to overwrite, it will overwrite only two consecutive files. I believe it has something to do with hitting "Enter", but I just have no clue...
if(((int)getHeader.deleted - 48) == 0) {
if(access(getHeader.file_name, F_OK) != -1) { /* File exists in directory, check for overwrite */
printf("%s already exists. Would you like to overwrite it? (y/n)\n", getHeader.file_name);
scanf("%c", buffer);
while(!validResponse) {
if(buffer[0] == 'y' || buffer[0] == 'Y') {
validResponse = 1;
printf("DO SOMETHING - Files will be overwritten\n");
} else if(buffer[0] == 'n' || buffer[0] == 'N') {
validResponse = 1;
printf("DO SOMETHING - File will be skipped\n");
} else {
printf("Invalid response... Would you like to overwrite %s? (y/n)\n", getHeader.file_name);
scanf("%c", buffer);
} /* End if else */
} /* End while */
} /* End if */
} /* End if */