I have been trying to create a routine that can pass data from one function to another to save user input data however passing the variable data from char save to char data_out[] leads to a Constant Expression expected error on said line of code. This code also causes a { expected error but I am unsure where it exactly wants the curly brackets since I know my code is correctly formatted.
Some steps I have taken to resolve this issue include adding the curly brackets around the save variable but they only resolved the { expected error but not the constant expression error. I have tweaked the code in a variety of ways to try to find the cause of the problem but that only caused more errors. My intention for the the code to be able to save data from the addition function if the user requests it later on. Any info will help, thanks!Code:int integer1; int integer2; int integer3; int option; char save; char c; FILE *fp; void get2nums() { printf("FIRST NUMBER?\n"); scanf("%d", &integer1); printf("SECOND NUMBER?\n"); scanf("%d", &integer2); } void addition() { get2nums(); integer1 + integer2 == save; printf("%d", integer1 + integer2); printf("\n"); static void savedata(void) { char data_out[] = save; _filetype = 's'; if ((fp = open ("CALCDATA", "w")) == 0) { printf("File could not be opened\n\r"); exit(1); } fwrite (data_out, 1, sizeof (data_out), fp); fclose (fp); }
Note I included the text file on accident and don't know how remove it, it is not relevant.