Menu not working properly - c

#include <stdio.h>
#include <stdlib.h> //for the clear screen function
#include <string.h>
struct customer
{
int custID;
char custName[50];
char custAddress[100];
};
typedef struct customer c;
void load_menu(void);
void customers_menu(void);
void createNew(void); //initialize your file
void add_Customer(c c1[30]); //add a new record to the file
FILE *fp;
int main(void)
{
load_menu();
return 0;
}
void load_menu(void)
{
int choice;
do
{
printf("Customer Orders Main Menu. \n\n");
printf("Please enter your choice: \n");
printf("1. Customer's Menu \n");
printf("2. Orders Menu\n");
printf("3. Product Stock Menu\n");
printf("4. Exit\n");
printf("\n");
if (scanf("%d",&choice)==1)
{
switch(choice)
{
case 1: system ("cls");
customers_menu();
printf("\n");
break;
case 2: system ("cls");
orders_menu();
printf("\n");
break;
case 3: system ("cls");
stock_menu();
printf("\n");
break;
case 4: printf("Quitting program!\n");
break;
default: printf("Invalid choice! Please try again\n");
printf("\n");
break;
}
}
else
{
fflush(stdin);
printf("Characters are invalid, please enter a number: \n ");
choice=0;
}
}while((choice !=4));
}
void createNew(void)
{
FILE *fp;
fp=fopen("Customer.dat", "w");
if (fp==NULL)
printf("File creation failed! \n");
else
{
printf("File created! \n");
fclose(fp);
}
}
void add_Customer (c c1[30])
{
int i, n , cc=0;
FILE *fp;
fp=fopen("Customer.dat", "a");
system("cls");
if(fp==NULL)
{
printf("File Creation Failed!");
}
system("cls");
printf("Enter the number of Customers: ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("Customer's ID (numbers only) : ");
scanf("%d", &c1[i].custID);
printf("Customer's Name : ");
gets(c1[i].custName);
printf("Customer's Address : ");
gets(c1[i].custAddress);
fwrite(&c1[i], sizeof(c), 1, fp);
}cc++;
fclose(fp);
}
void recordCount(c c1[30], int *count)
{
add_Customer(c1);
count=0;
count++;
}
void customers_menu(void)
{
int choice;
c c1[30];
int i;
do
{
printf("\n");
printf("Customers Menu \n\n");
printf("Please enter your choice: \n");
printf("1. Add Customer \n");
printf("2.\n");
printf("3.\n");
printf("4. Go back to Main Menu \n");
recordCount (c1, &i);
if (scanf("%d",&choice)==1)
{
switch(choice)
{
case 1: add_Customer(c1);
createNew();
printf("\n");
break;
case 2:
printf("\n");
break;
case 3:
printf("\n");
break;
case 4: printf("Going back to Main Menu\n");
system ("cls");
break;
default: printf("Invalid choice! Please try again\n");
printf("\n");
break;
}
}
else
{
fflush(stdin);
printf("Characters are invalid, please enter a number: \n ");
choice=0;
}
}while((choice !=4));
I have a problem since when I enter the Customers Menu it is staring to execute case 1 immediately (which still doesn't work properly). Can someone help me fix this error please because I tried everything I know and it is still in vain

I think your issue is that in customers_menu() you output the menu, but do not read the selection, instead you call recordCount() which directly calls addCustomer().
After addCustomer() we return the customers_menu() which then calls scanf() for the long gone menu.
A few other notes:
gets() is not good, I suggest you use scanf() (with %s) instead.
Doing a printf() then clearing the screen is a bit pointless.
Error messages should really go to stderr (fprintf(stderr,...)) rather than stdout (printf(...))
You code is a missing trailing }.
cc is added to, but not used.

This problem coming from if (scanf("%d",&choice)==1) because scanf will not return choice. If you enter valid answer (like number), then it returns 1 and switch case work with 1. I think that's the problem.
If you enter char instead of integer, scanf will return 0.

Related

Bugs in C Switch Menu using a Char as Choice, Won't Read in fgets name

Im basically Writing a program that creates, reads, updates and
deletes records in a binary file.
Everything compiles correctly, no syntax errors, but I do have some
bugs.
KNOWN BUGS
1.) Imputing any strings does not work, using fgets
2.) Ctrl-D Does Work but outputs a 'default' error before it exits.
3.) Update does not work (Not my main issue at the moment as the others are more important for now.)
4?) I'm not sure if the menu is working how it's supposed to work. I
think the do while is correct, since in the menu if I select and hit
CTRL-D it does exit the program. Just wanna be sure.
Right now I just want to know why, It is skipping the courseName in
the inputs function.
Here is my code thus far
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
typedef struct{
char courseName [64];
char courseSched [4];
unsigned int courseHours;
unsigned int courseSize;} COURSE;
FILE *pfileCourse;
int courseNumber = 0;
//Prototypes
void inputDetails(COURSE *c);
void readCourseRecord();
void createCourseRecord();
void print_menu();
void modifyCourseInfo();
void deleteCourse();
void display(COURSE c);
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char choice; // this is the choice
printf("Enter one of the following actions or press CTRL-D to exit\n");
printf("C - Create a new course record\n");
printf("R - Read an existing course record\n");
printf("U - Update an existing course record\n");
printf("D - Delete an existing course record\n");
do{
choice = getchar();
switch(choice) {
case 'c':
case 'C':
printf("YOU PICKED C for Create\n");
createCourseRecord();
break;
case 'r':
case 'R':
printf("This is Choice R\n");
readCourseRecord();
break;
case 'u':
case 'U':
printf("Here is where you update an existing course\n");
modifyCourseInfo();
break;
case 'd':
case 'D':
printf("here is where you Delete an existing course record\n");
deleteCourse();
break;
default:
printf("Wrong Choice!\n");
}
}while(choice != EOF);
return 0;
}
void createCourseRecord() {
COURSE data;
pfileCourse = fopen("courses.dat", "ab");
printf("Please Enter The Details of The Course\n");
inputDetails(&data);
fwrite(&data, sizeof(data), 1, pfileCourse);
fclose(pfileCourse);
printf("Course Has Been Created!\n");
}
void inputDetails(COURSE *c) {
printf("Enter a course number: \n");
scanf("%d", &courseNumber);
printf("Enter a Course Name: \n");
fgets(c->courseName, sizeof(courseName), stdin);
printf("Enter the course schedule (MWF or TR): \n");
fgets(c->courseSched, 4, stdin);
fflush(stdin);
printf("Enter the course credit hours: \n");
scanf("%d",&c->courseHours);
fflush(stdin);
printf("Enter Number of Students Enrolled: \n");
scanf("%d",&c->courseSize);
return;
}
void readCourseRecord(){
COURSE data;
int flag = 0;
int readCourseNumber = 0;
printf("Please Enter a Course Number to Display\n");
scanf("%d", &readCourseNumber);
fflush(stdin);
pfileCourse = fopen("courses.dat", "rb");
while((fread(&data, sizeof(data), 1, pfileCourse)) > 0) {
if(readCourseNumber == courseNumber)
{
display(data);
flag = 1;
}
}
fclose(pfileCourse);
if(flag == 0)
printf("Course not Found!\n");
}
void deleteCourse(){
int newCourseNum;
COURSE data;
FILE *file2;
printf("Please Enter The Course You Wish You Delete\n");
scanf("%d", &newCourseNum);
pfileCourse = fopen("courses.dat", "rb");
file2 = fopen("temp.dat", "wb");
rewind(pfileCourse);
while((fread(&data, sizeof(data), 1, pfileCourse)) > 0)
{
if(courseNumber != newCourseNum)
{
fwrite(&data, sizeof(data), 1, file2);
}
}
fclose(file2);
fclose(pfileCourse);
remove("courses.dat");
rename("temp.dat", "courses.dat");
printf("%d was Successfully deleted\n", newCourseNum);
}
void modifyCourseInfo()
{
COURSE data;
int newCourseNum, found = 0;
printf("Modify\n");
printf("Please Enter The Course You Wish You Modify\n");
scanf("%d", &newCourseNum);
pfileCourse = fopen("courses.dat", "rb+");
while ((fread(&data, sizeof(data), 1, pfileCourse)) > 0 && found == 0)
{
if (courseNumber == newCourseNum)
{
display(data);
printf("Please Enter New Details\n");
inputDetails(&data);
fseek(pfileCourse, - (long)sizeof(data), 1);
fwrite(&data, sizeof(data), 1, pfileCourse);
printf("Course Updated\n");
found == 1;
}
}
fclose(pfileCourse);
if(found == 0)
printf("ERROR: course not found\n");
}
void display(COURSE c){
printf("courseNumber:\t %d\n", courseNumber);
printf("courseName:\t %s\n",c.courseName);
printf("courseSched:\t %s\n",c.courseSched);
printf("courseName:\t %d\n",c.courseHours);
printf("courseSize:\t %d\n",c.courseSize);
}
It doesn't skip courseName, courseName just gets value '\n' because scanf function stops reading your input BEFORE white space. Scanf ignores any whitespace characters encountered before the next non-whitespace character. So you can just add
scanf("%d[^\n]", &courseNumber);
getchar();
after every scanf you have but I'd recommend you to use fgets function for every interactive input.

Why my C program crash

I am using "dev cpp" and i'm writing some codes in c
While I'm running the code below, after entering all data in the function 1, the exe file just crash.
there are not error shown before i finish entering all the data ad press enter
What is happening?
// hotel system *work in progress*//
#include<stdio.h>
#include<stdlib.h>
struct book
{
int bookno[20];
char travellername[20];
char destination[20];
char hotelname[20];
char checkin[20];
char checkout[20];
int guestno[20];
char type[20];
float fee;
}b;
void add();//Add new booking
void all(); //view all booking
//void mod(); modify booking
//void search(); search booking
//void del(); delete booking
void main()
{
int choose;
do{
printf("\n *** Welcome to Hong Kong Hotek booking Record and Management System 2017 ***\n");
printf("\n *** This system is developed by CCIT4020 Class No.NL-?? Group No.?? ***");
printf("\n\n\n--<Basic functions>-- \n");
printf("\n1. Add New Hotel Booking Record(s): \n");
printf("\n2. Display All Hotel Booking Records: \n");
printf("\n3. Modify Hotel Booking Record(s): \n");
printf("\n4. Search Hotel Booking Record(s): \n");
printf("\n5. Delete Hotel Booking Record(s): \n");
printf("\n0. Quit: \n");
printf("\nWhat is your option (0-5)? ");
scanf("%d",&choose);
switch (choose)
{
case 1 :
add();
break;
case 2:
all();
break;
//case 3:
// mod();
//break;
//case 4:
// search();
//break;
//case 5:
// del();
//break;
case 0:
exit(0);
break;
default:
printf("Invalid choice! Please enter again!");
break;
}
}while(choose!=0);
}
void add()
{
FILE *fp;
struct book b;
printf("Hotel Booking number: ");
scanf("%s",b.bookno);
printf("Name of Traveller: ");
scanf("%s",b.travellername);
printf("Destination: ");
scanf("%s",b.destination);
printf("Name of Hotel: ");
scanf("%s",b.hotelname);
printf("Check-in Schedule: ");
scanf("%s",b.checkin);
printf("Check-out Schedule: ");
scanf("%s",b.checkout);
printf("Number of Guests: ");
scanf("%s",b.guestno);
printf("Room Type: ");
scanf("%s",b.type);
printf("Total Fee: ");
scanf("%s",b.fee);
fp=fopen("data.txt","a");
if(fp == NULL)
{
printf("There are no data file! please create one!");
}
else
{
fprintf(fp,"%s \n %s \n %s \n %s \n %s \n %s \n %s \n %s \n %s",b.bookno,b.travellername,b.destination,b.hotelname,b.checkin,b.checkout,b.guestno,b.type,b.fee);
printf("One Record Added!");
}
printf("\n");
fclose(fp);
}
void all()
{
char choose;
FILE *fp;
fp = fopen("data.txt","r");
if(fp == NULL)
{
printf("There are no data file!");
exit(1);
}
else
{
system("clear");
while( ( choose = fgetc(fp) ) != EOF )
printf("%c",choose);
}
fclose(fp);
}
Read your compiler messages:
The problem is here:
scanf("%s",b.fee);
The format specifier is %s, but b.fee is a float.
You need this:
scanf("%f", &b.fee);
There are likely more problems like that one. Check them out by yourself. Each scanfformat specifier must match the variable.

can you help me understand about fopen("contact.dll", "r");

I'm trying to implement phonebook in C using data structure.
I found some source code and I'm trying to understand this code but there is really big problem I've never seen. It is dll. I googled about dll but there is nothing related about this. I know the meaning and purpose of dll, but why do we use fopen contact.dll ?
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
#include<dos.h>
struct contact
{
long phone;
char name[20],add[20],email[30];
} list;
char query[20],name[20];
FILE *fp, *ft;
int i,n,ch,l,found;
int main()
{
main:
system("cls"); /* ************Main menu *********************** */
printf("\n\t **** Welcome to Contact Management System ****");
printf("\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t[1] Add a new Contact\n\t\t[2] List all Contacts\n\t\t[3] Search for contact\n\t\t[4] Edit a Contact\n\t\t[5] Delete a Contact\n\t\t[0] Exit\n\t\t=====================\n\t\t");
printf("Enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 0:
printf("\n\n\t\tAre you sure you want to exit?");
break;
/* *********************Add new contacts************ */
case 1:
system("cls");
fp=fopen("contact.dll","a");
for (;;)
{
fflush(stdin);
printf("To exit enter blank space in the name input\nName (Use identical):");
scanf("%[^\n]",&list.name);
if(stricmp(list.name,"")==0 || stricmp(list.name," ")==0)
break;
fflush(stdin);
printf("phone:");
scanf("%ld",&list.phone);
fflush(stdin);
printf("address:");
scanf("%[^\n]",&list.add);
fflush(stdin);
printf("email address:");
gets(list.email);
printf("\n");
fwrite(&list,sizeof(list),1,fp);
}
fclose(fp);
break;
/* *********************list of contacts************************* */
case 2:
system("cls");
printf("\n\t\t================================\n\t\t\tLIST OF CONTACTS\n\t\t================================\n\nName\t\tphone No\t Address\t\tE-mail ad.\n=================================================================\n\n");
for(i=97; i<=122; i=i+1)
{
fp=fopen("contact.dll","r");
fflush(stdin);
found=0;
while(fread(&list,sizeof(list),1,fp)==1)
{
if(list.name[0]==i || list.name[0]==i-32)
{
printf("\nName\t: %s\nphone\t: %ld\nAddress\t: %s\nEmail\t: %s\n",list.name,
list.phone,list.add,list.email);
found++;
}
}
if(found!=0)
{
printf("=========================================================== [%c]-(%d)\n\n",i-32,found);
getch();
}
fclose(fp);
}
break;
/* *******************search contacts********************** */
case 3:
system("cls");
do
{
found=0;
printf("\n\n\t..::CONTACT SEARCH\n\t===========================\n\t..::Name of contact to search: ");
fflush(stdin);
scanf("%[^\n]",&query);
l=strlen(query);
fp=fopen("contact.dll","r");
system("cls");
printf("\n\n..::Search result for '%s' \n===================================================\n",query);
while(fread(&list,sizeof(list),1,fp)==1)
{
for(i=0; i<=l; i++)
name[i]=list.name[i];
name[l]='\0';
if(stricmp(name,query)==0)
{
printf("\n..::Name\t: %s\n..::phone\t: %ld\n..::Address\t: %s\n..::Email\t: %s\n",list.name,list.phone,list.add,list.email);
found++;
if (found%4==0)
{
printf("..::Press any key to continue...");
getch();
}
}
}
if(found==0)
printf("\n..::No match found!");
else
printf("\n..::%d match(s) found!",found);
fclose(fp);
printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");
scanf("%d",&ch);
}
while(ch==1);
break;
/* *********************edit contacts************************/
case 4:
system("cls");
fp=fopen("contact.dll","r");
ft=fopen("temp.dat","w");
fflush(stdin);
printf("..::Edit contact\n===============================\n\n\t..::Enter the name of contact to edit:");
scanf("%[^\n]",name);
while(fread(&list,sizeof(list),1,fp)==1)
{
if(stricmp(name,list.name)!=0)
fwrite(&list,sizeof(list),1,ft);
}
fflush(stdin);
printf("\n\n..::Editing '%s'\n\n",name);
printf("..::Name(Use identical):");
scanf("%[^\n]",&list.name);
fflush(stdin);
printf("..::phone:");
scanf("%ld",&list.phone);
fflush(stdin);
printf("..::address:");
scanf("%[^\n]",&list.add);
fflush(stdin);
printf("..::email address:");
gets(list.email);
printf("\n");
fwrite(&list,sizeof(list),1,ft);
fclose(fp);
fclose(ft);
remove("contact.dll");
rename("temp.dat","contact.dll");
break;
/* ********************delete contacts**********************/
case 5:
system("cls");
fflush(stdin);
printf("\n\n\t..::DELETE A CONTACT\n\t===============================\n\t..::Enter the name of contact to delete:");
scanf("%[^\n]",&name);
fp=fopen("contact.dll","r");
ft=fopen("temp.dat","w");
while(fread(&list,sizeof(list),1,fp)!=0)
if (stricmp(name,list.name)!=0)
fwrite(&list,sizeof(list),1,ft);
fclose(fp);
fclose(ft);
remove("contact.dll");
rename("temp.dat","contact.dll");
break;
default:
printf("Invalid choice");
break;
}
printf("\n\n\n..::Enter the Choice:\n\n\t[1] Main Menu\t\t[0] Exit\n");
scanf("%d",&ch);
switch (ch)
{
case 1:
goto main;
case 0:
break;
default:
printf("Invalid choice");
break;
}
return 0;
}
Judging by the way the file is used, contact.dll is not an actual Windows DLL, but a datafile that this application used to store phonebook entries.
The various cases add, remove, update, and retrieve list entries from the file. The name given to the file is misleading.

modify record in a file using c program

I've written this c program to insert, view, modify and delete the records in a file. File name is emp.dat. The code for displaying, adding and deleting is working fine but the modify part is not working. The program asks to input details to modify but nothing gets updated/modified.
The Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
void main()
{
FILE *outp,*inpt;
char another,choice;
struct emp
{
int emp_no,age;
char name[40];
float bs;
};
struct emp e;
char empname[40];
long int recsize;
outp=fopen("emp.dat","r+");
if(outp=='\0')
{
outp=fopen("emp.dat","w+");
if(outp=='\0')
{
puts("cannot open file\n");
exit(1);
}
}
recsize=sizeof(e);
while(1)
{
printf("1.Add records\n");
printf("2.List records\n");
printf("3.Modify records\n");
printf("4.Delete records\n");
printf("0. exit\n");
printf("Your choice\n");
fflush(stdin);
choice=getche();
switch(choice)
{
case '1': //code to add data
.
case '2': //code to display data
case '3': //code to modify data
another='Y';
while(another=='Y')
{
printf("\nEnter name of employee to modify");
scanf("%s",empname);
rewind(outp);
while(fread(&e,recsize,1,outp)==1)
{
if(strcmp(e.name,empname)==0)
{
printf("\nenter new name,age & gs");
scanf("%d %s %d %f",&e.emp_no,&e.name,&e.age,&e.bs);
fseek(outp,-recsize,SEEK_CUR);
fwrite(&e,recsize,1,outp);
break;
}
}
printf("\nModify another record(Y/N)");
fflush(stdin);
another=getche();
}
printf("\n\n");
break;
case '4': //code to delete data
case '0':
fclose(outp);
printf("\n\n");
exit(1);
}
}
}
As can be seen in output the name doesn't change from Zaid to Cow, so does the age and gs
You really should test the return values.
The prompt asks for name,age & gs, and you enter them as asked. However scanf is instructed to get an integer (emp_no) first ("%d %s %d %f"). Missing that it fails immediately and nothing gets updated.
The situation is easily detectable: scanf returns the number of successful conversions.

Correction request for C Program

// I'm having issues compiling my program. Honestly, i'm a new programmer and i'm not really sure how to use certain things within my program. Can someone check my program and give me the corrections please or better thoroghly explain it ti me? It's neede for monday..//
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
int main()
{
//File declarations//
FILE*Log;
FILE*Inventory;
FILE*Username;
char fpass_word[10]="invent";
char fusername[10]="";
//Declarations for variables//
int main;
int sub_main;
int s=0;
int s_goods;
int p_goods;
int in_goods;
int c_goods;
double Unit_price;
int item_quantity;
int invoice_num;
char pass_word1[10]=" ";
char pass_word[10]="invent";
char username[10]="inventor";
char username1[10]=" ";
char Supplier[12]=" ";
char Items_name[12]=" ";
char Invoice_date[10]=" ";
//Declarations for variables//
int u=0;
int count=0;
int option;
int choice;
int choice1;
int m=0;
int Save;
int New_inventory;
int Update_inventory;
int Print;
int Close_Program;
int t_sales;
int t_purchases;
double m_sales[4]={30000.00,50000.00,100000.00,120000.00};
}
Log=fopen("Invent.txt","w")
if(Log==NULL)
printf("File does not exist");
}
else
{
fprintf(Log,"%s",pass_word);
fclose(Log);
}
user=fopen("Username.txt","w")
if(user==NULL)
{
printf("File does not exist");
}
else
{
fprintf(user,"%s",username);
fclose(user);
}
printf("__________________________________________________________\n\n");
printf("************Please login to your account!************\n\n");
printf("__________________________________________________________\n\n");
printf("Please enter your username: \n");
scanf("%s",username);
user=fopen("Username.txt","r")
{
if(user==NULL)
{
printf("File does not exist");
}
else
{
fprintf(user,"%s",fusername);
fclose(user);
}
choice1=strncmp(username,fusername,10);
printf("Please enter password: \n");
scanf("%s",pass_word1);
Log=fopen("Invent.txt","r")
if(Log==NULL)
{
printf("File does not exist");
}
else
{
fscanf(Log,"%s",fpass_word);
fclose(Log);
}
choice=strncmp(pass_word1,fpass_word,10);
while (choice!=0 && count<3)
{
printf("*************************************************************************************\n\n");
printf("!!!!!!!!!!!!!!!!!!!!!!!!Please re-enter your login info!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
printf("*************************************************************************************\n\n");
printf(" Please enter username: \n");
scanf("%s",&username);
choice=strncmp(username,username1,10);
printf("Please enter password!\npassword:");
scanf("%s",pass_word);
choice=strncmp(pass_word,pass_word1,10);
count=count++;
//menu function!!!
getch();
system("cls");
}//login page
printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
printf("\n******************** Welcome to the INVENT BIZ main page!********************\n\n");
printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
printf (">>>>>>>>>>>>>>> Please select an option you desire:<<<<<<<<<<<<<<<\n\n");
printf("1: New inventory\n");
printf("2: Update inventory\n");
printf("3: Print\n");
printf("4: Save \n");
printf("5: Close Program\n");
printf("Please select an option: \n");
scanf("%d",&option);
//menu screen
while(option!=6)
{
switch(main)
{
case 1:
printf("New inventory");
Inventory=fopen("New Inventory.txt","w")
if (Inventory==NULL)
printf("This File is empty!");
}
else
{
fprintf("Please enter invoice date:\t\n");
fprintf("Please enter Supplier:\t\n");
fprintf("Please enter Item name:\t\n");
fprintf("Please enter quantity of items:\t\n");
fprintf(" Please enter invoice number:\t\n");
fprintf("Please enter Unit Price:\t\n");
}
fclose(Inventory);
// Data entered for inventory//
switch(sub-main)
{
case 10:
printf("Please enter sales for each month:%d",t_sales);
printf(" Total Sales\n");
scanf("%d",&t_sales);
break;
case 3:
printf("Print");
Inventory=fopen("New Inventory.txt","r")
fscanf(Inventory,"%d",Invoice_date);
fscanf(Inventory,"%s",Supplier);
fscanf(Inventory,"%s",Items_name);
fscanf(Inventory,"%d",&item_quantity);
fscanf(Inventory,"%d",&invoice_num);
fscanf(Inventory,"%d",&Unit_price);
fclose(Inventory);
break;
case 4:
printf("Save");
Inventory=fopen("Inventory1.txt","w");
if(Inventory==NULL)
{
printf("This file empty!!!");
}
else
{
printf("File saved");
}
fclose(Inventory);
case 5:
printf("Close Program");
exit(main);
break;
} // end switch
system("cls");
printf (">>>>>>>>>>>>>>> Please select an option you desire!!!<<<<<<<<<<<<<<<\n\n");
printf("1: New inventory\n");
printf("2: Update inventory\n");
printf("3: Print\n");
printf("4: Save \n");
printf("Please select an option: \n");
scanf("%d",&option);
}
}
system("cls");
getch();
return ();
}
You should really be more specific and not just throw down an entire program and say you want to someone to clean it up for you.
Thank being said I noticed right away you had a few improperly placed curly braces. Your very first if statement is missing an opening brace and further down you have an unnecessary opening brace after user=fopen("Username.txt", "r")
Beyond that indentation is completely off throughout and your switch statements make it really hard to follow what it is you're trying to accomplish with them.
My advice is to read through the compiler errors and locate each issue one by one, and if you're having a problem you can't solve then be specific and post the errors you're getting with your program.

Resources