I am getting some build errors when I run this program that I do not know how to fix. There are two lines 22 and 32 that have this warning:22) : warning C4047: '=' : 'FILE *' differs in levels of indirection from 'errno_t' and a warning and an error for line 22 that say: warning C4024: 'fopen_s' : different types for formal and actual parameter 1 and 22) : error C2198: 'fopen_s' : too few arguments for call. Your assistance in correcting my code is appreciated!The idea is to have a user type the name of an input text file and an output text file.
#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("%s",input);
inf = fopen_s(input,"r");
/*Check for input file*/
if(inf==NULL)
{
printf("Input file not exists");
return 1;
}
printf("Enter output file name:");
scanf_s("%s",output);
ouf = fopen_s(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()
{
int i=0;
printf("Reading from file");
/*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]);
}
}

New Topic/Question
Reply




MultiQuote






|