It show a errror on the void read function with the { as the error. What do i nedd to do to fix it?
Code:
#include <stdio.h>
#include <stdlib.h> //malloc is usually in here
#include <string.h>
int list_length = 0; //keeps track of the number of names
void read_file(char **nameslist);
void save(char **list);
void sort_list(char**list,int n);
int main() {
char *list[60]; //creates a list of 60 char pointers
char choice;
read_file(list); //reads the names from the file
FILE*f1;
f1=fopen("nameslist.txt","w");
if(f1== NULL){
printf("Can't open nameslist.txt");
exit(0);
}
/*****************************************************
function: reads names in from a file
parameters: list is an array of char pointers
returns: none
comments:Reads the names in from the file then it
arranges the names and put it in a file.
******************************************************/
void read_file(char **list){
int i;
char fname[60], mname[60], lname[60];
for(i = 0; fscanf(p,"%s %s %s", &fname, &mname, &lname) == 3; i++) { //reads in the names as first,middle,and last
list[1] = malloc(strlen(fname) + strlen(mname)+ strlen(lname) + 3);
strcpy(list[1],fname); //arranges the names as "first middle last"
strcat(list[1]," ");
strcat(list[1],mname);
strcat(list[1]," ");
strcat(list[1],lname);
}
mname[0]
mname[1]='.'
mname[2]='\0'
list[2] = malloc(strlen(lname) + strlen(mname) + srtlen(fname) + 3);
strcpy(list[2],lname);
strcat(list[2]," ");
strcat(list[2],mname);
strcat(list[2]," ");
strcat(list[2],fname);
FILE *fp=fopen("nameslist.txt","r+");
FILE *fp2=fopen("phonebook.txt","w");
if((fp == NULL)||(fp2 == NULL)){
printf("\nError opening files.\n");
exit(0);
}
}
}
/********************************************************
function: arranges the names in list so that the last
name is replaced by its initial
parameters: list is an array of char pointers
returns: none
comments: This functions sorts the names alphabetically
and then saves them in a file.
********************************************************/
void sort_list(char**list,int n){
int i,j;
char temp[30];
for(i=1;i<n;i++){
strcpy(temp,list[i]);
for(j=i;(j>0)&&(strcmp(list[j-1],temp)>=0);j--){
strcpy(list[j],list[j-1]);
}
strcpy(list[j],temp);
}
FILE *fp=fopen("nameslist.txt","r+");
FILE *fp2=fopen("alphabet.txt","w");
if((fp == NULL)||(fp2 == NULL)){
printf("\nError opening files.\n");
exit(0);
}
}