Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the expected output of this programm was supposed to be a menu promted to let user press 1 or 2 and execute the program but

the expected output of this programm was supposed to be a menu promted to let user press 1 or 2 and execute the program but when i run this c program the compiler does not shoe error nor menu. canu anyone please workout to reslove the issue the details are given below:-

Programfinishedwithexitcode0

PressENTERtoexitconsole

but the program was supposed to promt from this line.

printf("Menu - ");

printf("1. Please enter the name ");

printf("2. Please press to output csv file and exit. ");

printf("Enter your choice :");

THIS IS THE CODES IN C PROGRAMMING LANGUAGE NOT C++

#include

#include

#include

#define MAXCHAR 100

int equalsIgnoreCase(char a[], char b[]) {

for (int i = 0; a[i]; i++)

a[i] = tolower(a[i]);

for (int i = 0; b[i]; i++)

b[i] = tolower(b[i]);

if (strcmp(a, b) == 0) {

return 1;

}

return 0;

}

int main()

{

FILE* pInputFile;

FILE* pOutputFile;

errno_t err;

int chr = 0;

char nameList[MAXCHAR][10];

int centList[MAXCHAR];

int pos = 0;

if ((err = fopen_s(&pInputFile, "input.txt", "r")) == 0)

{

while (fscanf_s(pInputFile, "%s", nameList[pos], sizeof(nameList[pos])) == 1) {

//printf("%s", listnames[pos]);

fscanf_s(pInputFile, "%d", ¢List[pos], sizeof(centList[pos]));

//printf("%d", listcents[pos]);

pos++;

}

}

else {

exit(0);

}

fclose(pInputFile);

fopen_s(&pOutputFile, "change.csv", "w");

if (pOutputFile == NULL) {

exit(0);

}

while (1)

{

printf("Menu - ");

printf("1. Please enter the name ");

printf("2. Please press to output csv file and exit. ");

printf("Enter your choice :");

int choice;

scanf_s("%d", &choice);

//printf("%d", choice);

if (choice == 1)

{

printf("Enter name : ");

char name[MAXCHAR];

scanf_s("%s", name, sizeof(name));

int isNameFound = 0;

for (int i = 0; i < pos; i++)

{

// i created a equalsIgnoreCase method is bottom

if (equalsIgnoreCase(nameList[i], name) == 1)

{

isNameFound = 1;

int cents = centList[i];

int fifty = cents / 50;

cents = cents % 50;

int twenty = cents / 20;

cents = cents % 20;

int tens = cents / 10;

cents = cents % 10;

int five = cents / 5;

printf("%s %d cents ", nameList[i], centList[i]);

printf("50 cents = %d, 20 cents = %d,10 cents = %d, 5 cents = %d ", fifty, twenty, tens, five);

}

}

if (!isNameFound)

{

printf("Name not found ");

}

}

else if (choice == 2)

{

for (int i = 0; i < pos; i++)

{

int cents = centList[i];

int fifty = cents / 50;

cents = cents % 50;

int twenty = cents / 20;

cents = cents % 20;

int tens = cents / 10;

cents = cents % 10;

int five = cents / 5;

printf("%s %d cents ", nameList[i], centList[i]);

printf("50 cents = %d, 20 cents = %d,10 cents = %d, 5 cents = %d ", fifty, twenty, tens, five);

//print the file

fprintf(pOutputFile, "%s,%d,%d,%d,%d,%d ", nameList[i], centList[i], fifty, twenty, tens, five);

}

fclose(pInputFile);//close the file

break;

}

else

{

printf("Invalid choice ");

}

}

}

input fille (input.txt)

sona

70

rahul

50

suman

90

indra

60

sunil

65

sandip

85

vipin

75

janaki

30

rohit

30

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

What are the three substitutes for leadership?

Answered: 1 week ago

Question

Find the unit vector in the opposite direction of (1,2,3)

Answered: 1 week ago