I was doing some tests with Files in C, and one of these tests was to create a file with the name insterted by the user, but I noticed that every file I created with the insrted name finished with "?". I'm assuming it's a special character, since I have never insterted a question mark in the path string I used to get the path to the file, but I'm not sure what this character is, and I'm curious to know how to remove it from the string.
I also noticed that this code created the file even if it doesn't exists. I don't know why.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
const int DIM = 1024;
int main()
{
FILE *fp;
char c;
char path[DIM];
do
{
printf("\nFile path: ");
fgets(path, 1024, stdin);
fp = fopen(path, "w");
if(fp == NULL)
{
perror("Error: ");
free(fp);
printf("Retry? [y/n]");
scanf("%c", &c);
getchar();
}
}while(c == 'y' || c == 'Y');
}