Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I will rate 5 stars if answered correctly, solve efficiently but correctly Follo

ID: 3536367 • Letter: I

Question

I will rate 5 stars if answered correctly, solve efficiently but correctly


Follow ALL STEPS FOR 5 STARS


Write an application that reads in n names and determines


If any two are the same


the main function, main2.c, will read in the names by calling the readLine function


prompt the user to enter at least five names


each time a name is entered malloc the space in char *person[MAXNAMES] for the string containing the name.


main3.c will compare the names and print out any two name that are same independent of upper or lower case.
create only one file,


main2.c, which will contain two functions main and readLine

int readLine(char name[], int maxChar)
{
int ch;
int i = 0;
while ( (ch = getchar()) !- ' ' )
{
if ( i < maxChar )
name[i++] = ch;
}
name[i] = ''; // terminates string
return i; // returns number of characters stored
} // end readLine

Explanation / Answer

//main2.c

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include"main3.c"

#define MAXNAMES 30

#define MAXLENGTH 60

int readline(char [],int);

int main()

{

int i,n;

char name[MAXLENGTH];

char *person[MAXNAMES];

printf("How many name u want to enter (Enter the atleast five name) ");

scanf("%d",&n);

printf("Enter %d names ",n);

fflush(stdin);

for(i=0;i<n;i++)

{

person[i]=malloc(sizeof(char)*(readLine(name,MAXLENGTH)));

strcpy(person[i],name);

}

compare(person,n);

system("pause");

}



int readLine(char name[], int maxChar)

{

int ch;

int i= 0;

while ( (ch = getchar())!=' ' )

{

if ( i < maxChar )

name[i++] = ch;

}

name[i] = ''; // terminates string

return i; // returns number of characters stored

} // end readLine