I had made a program that creates a file with name given by a user.
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
int g;
char file[15];
fgets(file,15,stdin);
g=open(file,O_CREAT | O_WRONLY,__S_IWRITE);
}
But it creates a file with a filename with some garbage character at the end. How can I correct this?
here is sample run:
$ ./a.out
coolfile.txt
$ ls
a.out coolfile.txt? test.c
the same program but just using gets function gives correct filename but I had heard that gets should not be used.