I am trying to test fwrite. I am trying to write a usecase in which fwrite fails. Here is waht i tried.
#include <stdio.h>
#include <errno.h>
int main()
{
char arr[6] = "manty";
int ret;
FILE *fp;
printf("Before fwrite - errno - %d\n", errno);
// fp = fopen("fwrite_test.txt", "w+");
ret = fwrite(arr, sizeof(arr) + 2, 1, fp);
printf ("ret - %d errno - %d ferror - %d\n", ret, errno, ferror(fp));
return 0;
}
By wantedly commenting fopen() I thought fwrite will return an error. But it gives a segmentation fault.
How cani test fwrite()?