As informed by Oli's comment and Paul R's comment, I added the appropriate error handling:
fp = fopen("~/my.txt", "w");
if (fp == NULL)
{
perror ("The following error occurred");
printf( "Value of errno: %d\n", errno );
return EXIT_FAILURE;
}
And the output was:
The following error occurred: No such file or directory
Value of errno: 2
After fixing the file path to a full path, the call to setvbuf
was successful.