Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
int main()
{
char *options[100], *as[100], *bs[100], *cs[100], *Xos[100], *Yos[100], *Zos[100], *filename[20];//the s at the end of the name tell me it is stored as a string.
float a, b, c, Xo, Yo, Zo;
FILE *recentdata, *EulerData;//pointer to store recent data in text file.
while (1)
{
menu();
scanf("%99s", options);
//What to do if user types exit
if(strcmpi(options,"exit") == 0)//compare options to "recent" NOT case sensitive.
{
exit(0);
}
//What to do if user types q
else if(strcmpi(options,"q") == 0)//compare options to "recent" NOT case sensitive.
{
system("cls");
}
//What to do if user types recent
else if(strcmpi(options,"recent") == 0)//compare options to "recent" NOT case sensitive.
{
recentdata = fopen("recentdata.txt", "r");
fscanf (recentdata, "%s %s %s %s %s %s", as, bs, cs, Xos, Yos, Zos);
fclose;
}
//if the user didnt type recent, they typed something else in...?
else
{
strcpy(as,options);//copy the value of options into as.
scanf("%99s", bs);
scanf("%99s", cs);
printf ("%s %s %s\n\n", as, bs, cs);
printf("Please input Xo, Yo and Zo\n");
scanf("%99s", Xos);
scanf("%99s", Yos);
scanf("%99s", Zos);
printf ("%s %s %s\n\n", Xos, Yos, Zos);
recentdata = fopen("recentdata.txt", "w");
fprintf(recentdata, "%s %s %s %s %s %s\n", as, bs, cs, Xos, Yos, Zos);
fclose;
}
a=atof(as); //converting strings to floats so that the compiler understands it is a number that can be used mathematically.
b=atof(bs);
c=atof(cs);
Xo=atof(Xos);
Yo=atof(Yos);
Zo=atof(Zos);
printf (" a = %.2f\n b = %.2f\n c = %.2f\nXo = %.2f\nYo = %.2f\nZo = %.2f\n", a, b, c, Xo, Yo, Zo);
printf("Beginning execution of improved Euler...\n\n");
Sleep(1000);
printf("Please enter the name of the file to store the data in\n");
printf("If it doesnt exist, it will be created.\n\n");
scanf("%s", filename);
printf("\nStoring all Data in file '%s.txt'\n", filename);
Sleep(1000);
}
return 0;
}
int menu()
{
printf("Type 'recent' to use the last entered data or:\nInput a, b and c, hitting Enter between each one,\n");
printf("Typing 'q' at any time will bring you back here,\n");
printf("To exit the program, from this screen type 'exit'.\n");
return(1);
}