I'm trying to make a program that will ask the user to which file they want to sort, sort it, then output the sorted text into a user specified file. the text file will contain names and the program should make lowercase and uppercase letter the same.
#include<stdio.h>
#include<stdlib.h>
#define LEN 80
#define MAX_NAME 40
void EnterFile(char file[MAX_NAME][LEN]);
void ReadingFile(char file[MAX_NAME][LEN]);
int CompareStrings(char name1[LEN], char name2[LEN]);
void SwapStrings(char name1[LEN], char name2[LEN]);
void BubbleSort( char file[MAX_NAME][LEN]);
void OutputFile(char file2[MAX_NAME][LEN]);
void EnterFile(char file[MAX_NAME][LEN]){
FILE *pef;
printf("enter the name of the file to sort:");
scanf("%s", &file);
pef=fopen("file", "r");
if (pef == NULL) {
printf("I couldn't open %s.\n", file);
exit(0);}
}
void ReadingFile(char file[MAX_NAME][LEN]){
FILE *pef;
pef=fopen("file", "r");
char name;
while(fscanf(pef, "%s", name ) != NULL)
fclose(pef);
}
int CompareStrings(char s1[LEN], char s2[LEN]){
int i;
for(i=0; i<LEN; i++)
{ if (s1[i]>s2[i])
{ return(1); }
if (s1[i]<s2[i])
{ return(-1); }
if (s1[i] == 0 || s2[i] == 0)
{ break;}
}
}
void SwapStrings(char name1[LEN], char name2[LEN]) {
int i;
char c;
for(i=0; i<LEN; i++)
{ c = name1[i];
name1[i] = name2[i];
name2[i] = c;
}
}
void BubbleSort( char file[MAX_NAME][LEN]){
int p, i;
for(p=1; p<MAX_NAME; p++)
{ for(i=0; i<MAX_NAME-1; i++)
{ if (CompareStrings(file[i], file[i+1]) > 0)
{SwapStrings(file[i], file[i+1]);
}
}
}
}
void OutputFile(char file2[MAX_NAME][LEN]) {
FILE *fp;
int i;
char name;
printf("enter the name of the output file:\n");
scanf("%s", &file2);
fp=fopen("%d", "a");
printf( "Can't open %s", file2);
for(i=0; i<=LEN; ++i){
for(i=0; i< MAX_NAME; i++)
{print("%s", file2[i]);}
}
}
int main() {
int main() {
char file[LEN][MAX_NAME];
EnterFile(file);
ReadingFile(file);
CompareStrings(name);
BubbleSort(name);
OutputFile(name);
return 0;
}