I'm having quite a bit of trouble figuring out why my code won't work.
The objective of this program is to make a series of random sentences from the given arrays, and to then either output them to the screen or to a text file.
I'm not exactly sure what the problem is, but when I go to input a title for the file, I get an unhanded exception error.
In the case where I change the FILE**
stream parameter to NULL instead of write in fopen_s
, I get a debug assertion error.
I believe the problem lies with the way I've declared my pointer.
#include <.stdio.h>
#include <.conio.h>
int main()
{
char * article[5] = { "the", "one","some","any","a" };
char * noun[5] = { "boy","girl","dog","town","car" };
char * verb[5] = { "drove","jumped","ran","walked","skipped" };
char * preposition[5] = { "to","from","over","under","on" };
int x = 0;
char * output[100] = {0};
//char output = { "" };
FILE ** write = "C:\Users\dilli\Downloads\test.txt";
while (5) {
printf("Enter one(1) to output to screen, two(2) to output to file:\n");
scanf_s("%d",&x);
if(x==1)
printf_s("%s %s %s %s %s %s.\n", article[rand() % 5], noun[rand() % 5], verb[rand() % 5],
preposition[rand() % 5], article[rand() % 5], noun[rand() % 5]);
else if (x == 2)
{
printf("Enter name of output file:\n");
scanf_s("%s",&output,100);
printf("output:\n%s",output);
fopen_s(write,output, "w");//This is where we are getting an unhandled exception.
fprintf("%s %s %s %s %s %s.\n", article[rand() % 5], noun[rand() % 5], verb[rand() % 5],
preposition[rand() % 5], article[rand() % 5], noun[rand() % 5]);
fclose(write);
}
}
}