I am getting some build code errors I do not understand how to fix. This is probably because I am so new to programming. Help is appreciated! Line 54 error is missing semicolon before type and lines 56,59, and 60 say i is undeclared???
include<stdio.h>
#include<string.h>
//Global Variables
char array[10][20];
FILE *inf,*ouf;
int n;
//Function prototype
int ReadFile();
void Sort();
void WriteFile();
//Main Function
int main()
{
/*Reading user input*/
char input[20],output[20];
printf("Enter input file name:");
scanf("%s",input);
inf = fopen(input,"r");
/*Check for input file*/
if(inf==NULL)
{
printf("Input file not exists");
return 1;
}
printf("Enter output file name:");
scanf("%s",output);
ouf = fopen(output,"w");
/*Check for output file*/
if(ouf==NULL)
{
printf("Cannot create output file");
return 1;
}
/*Call functions*/
n = ReadFile();
Sort();
WriteFile();
/*Close files*/
fclose(inf);
fclose(ouf);
return 0;
}
/*Function to read data from file*/
int ReadFile()
{
printf("Reading from file");
int i=0;
//Read and store in array
while(fscanf(inf,"%s",array[i])!=EOF)
{
/*Display data*/
printf("%d - %s\n",i,array[i]);
i++;
};
return 1;
}
void Sort()
{ int i,j;
/*Bubble Sorting*/
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i;j++)
{
if(strcmp(array[j],array[j+1])>0)
{
/*Swapping*/
char *temp;
strcpy(temp,array[j]);
strcpy(array[j],array[j+1]);
strcpy(array[j+1],temp);
}
}
}
}
/*Function to write to the file*/
void WriteFile()
{
int i;
printf("Writing to file");
for(i=0;i<=n;i++)
{
/*Display data*/
printf("%s\n",array[i]);
fprintf(ouf,"%s\n",array[i]);
}
}