can somebody help me this code cannot run. I can't find the error...
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include<stdlib.h> //use for fflush and exit(0)
#include<string.h> //use for strcpy
void calculate();
void insert();
void exit();
#define TRUE 1
void calculate_and_sort(int end_of_file);
int input1;
char ch;
typedef struct{
int num;
char matrix[20];
double midterm;
double final;
double total;
char grade[10];
}input_t[30];
input_t input;
main()
{
char file_name[100];
int i = 0;
int condition2 = 0;
int condition = 0;
int end_of_file = 0;
char output_file_name[100];
int limit=3;
do
{
printf("\n________________________________________________________________________________");
printf("\n\n\t\tWELCOME TO OUR SYSTEM \n\n");
printf("__________________________________________________________________________________\n\n");
FILE *inp,
*outp;
do{
end_of_file = 0;
fflush(stdin); //flush off buffer
do{
printf("\nInsert file name to manipulate the file data (out of %d): ",limit);
gets(file_name);
inp = fopen(file_name,"r");
if(inp == NULL){
printf("\n '%s' doesn't exist...\n", file_name);
limit--;
if(limit == 0){
printf("\n\nSession end... more than 3 times inserting the invalid file name...");
exit(0);
}
}
}while(inp == NULL);
limit=3;
while( fscanf(inp, "%d%s%lf%lf", &input[i].num, &input[i].matrix, &input[i].midterm, &input[i].final) != EOF ){
end_of_file++;
i++;
}
//show scanned result...............................................................................................................
printf("\nResult Scanned\n");
printf("No\tMatrix\t Midterm Final\n");
for(i=0; i<end_of_file; i++){
printf("%d\t%s\t %.2f\t %.2f\n",input[i].num, input[i].matrix, input[i].midterm, input[i].final);
}
//show scanned result...............................................................................................................
printf( "\t\t1. CALCULATE\n\n" );
printf( "\t\t2. INSERT OTHER FILES\n\n" );
printf( "\t\t3. EXIT\n\n");
printf( "\tPlease Enter Your Selection: ");
scanf("%d",&input);
ch=toupper( getche() );
switch (input1) {
case 1 :
printf("\n__________________________________________________________________");
printf("\n\n\t\t CALCULATE \n\n");
printf("____________________________________________________________________\n\n");
printf("\nTo Calculate, Sort and Save... press '1'... ");
scanf("%d",&condition2);
fflush(stdin); //flush off buffer
if(condition2 == 1){
calculate_and_sort(end_of_file);
printf("\nInsert output file name (please include the file extention '_.txt'): ");
gets(output_file_name);
outp = fopen(output_file_name, "w");
fprintf(outp, "No\tMatrix\t Total\t Grade\n");
for(i=0; i<end_of_file; i++){
fprintf(outp, "%d\t%s\t %.2f\t %s\n",input[i].num, input[i].matrix, input[i].total, input[i].grade);
}
}
//calculating..........................................................................................................
printf("\nCalculated : \n");
for(i=0; i<end_of_file; i++){
input[i].total = input[i].midterm + input[i].final;
if(input[i].total >= 80 && input[i].total <= 100 ){
sprintf(input[i].grade, "A");
}
else if(input[i].total >= 75 ){
sprintf(input[i].grade, "A-");
}
else if(input[i].total >= 70 ){
sprintf(input[i].grade, "B+");
}
else if(input[i].total >= 65 ){
sprintf(input[i].grade, "B");
}
else if(input[i].total >= 60 ){
sprintf(input[i].grade, "B-");
}
else if(input[i].total >= 55 ){
sprintf(input[i].grade, "C+");
}
else if(input[i].total >= 50 ){
sprintf(input[i].grade, "C");
}
else if(input[i].total >= 45 ){
sprintf(input[i].grade, "C-");
}
else if(input[i].total >= 40 ){
sprintf(input[i].grade, "D+");
}
else if(input[i].total >= 35 ){
sprintf(input[i].grade, "D");
}
else if(input[i].total < 35 ){
sprintf(input[i].grade, "E");
}
else
sprintf(input[i].grade, "Error");
}
printf("No\tMatrix\t Total\t Grade\n");
for(i=0; i<end_of_file; i++){
printf("%d\t%s\t %.2f\t %s\n",input[i].num, input[i].matrix, input[i].total, input[i].grade);
}
break;
case 2:
printf("\n___________________________________________________________________");
printf("\n\n\t\t INSERT OTHER FILES \n\n");
printf("_____________________________________________________________________\n\n");
fflush(stdin); //flush off buffer
if(condition2 == 1){
calculate_and_sort(end_of_file);
printf("\nInsert output file name (please include the file extention '_.txt'): ");
gets(output_file_name);
outp = fopen(output_file_name, "w");
fprintf(outp, "No\tMatrix\t Total\t Grade\n");
for(i=0; i<end_of_file; i++){
fprintf(outp, "%d\t%s\t %.2f\t %s\n",input[i].num, input[i].matrix, input[i].total, input[i].grade);
}
break;
case 3: printf("\n\n\t\tProgram finished ");
break;
default: printf("\n\n\t\tIncorrect choice. Try again\n\n");
printf("\t\t----------------------------------------------------------\n\n\n");
continue;
}
if(input1==3)break;
}
getch();
}