im working on a project which includes adding , searching and display functions.
i got all codes of these functions but the problem is i cant merge it into one program..
can somebody help me merge it? your help is very much appreciated. ty!
heres the code:
CODE
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<ctype.h>
main()
{
FILE *SariSariStore;
int item_id;
char answer;
char item_name[50];
SariSariStore = fopen("c:\\myfolder\\sarisari.txt","a+");
do {
clrscr();
cout<<"Enter Item no.: ";
cin>>item_id;
cout<<"Enter Item name: ";
fflush(stdin);
gets(item_name);
cout<<"Do you want to save? Y/N: ";
cin>>answer;
if(toupper(answer)=='Y')
fprintf(SariSariStore,"%i %s \n", item_id, item_name);
}while(toupper(answer)!='N');
fclose(SariSariStore);
return 0;
}
// THIS IS THE CODE FOR DISPLAY
#include <stdio.h>
#include<iostream.h>
#include<conio.h>
main( )
{
FILE *SariSariStore;
char c;
clrscr();
SariSariStore = fopen("sarisari.txt", "r");
if (SariSariStore == NULL) printf("File doesn't exist\n");
else {
do {
c = getc(SariSariStore); // get one character from the file
putcharŠ; // display it on the monitor
} while (c != EOF); // repeat until EOF (end of file)
}
fclose(SariSariStore);
getch();
return 0;
}
//THIS IS THE CODE FOR SEARCH
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <iostream.h>
#include <ctype.h>
main()
{
FILE *SariSariStore;
int found = 0;
char name[100], target[100], name1[100];
clrscr();
SariSariStore = fopen("c:\\sarisari.txt" ,"r");
if(SariSariStore==NULL)
printf("File not found");
else
printf("Enter Name to Search : ");
fflush(stdin);
gets(target);
do
{
fscanf(SariSariStore,"%s %s",&name,&name1);
if(strcmp(name,target)==0)
{
found =1;
}
}while(!feof(SariSariStore) && found == 0);
if(found==1)
{
printf("Name: %s %s",name,name1);
}
else
printf("Not Found");
fclose(SariSariStore);
getch();
return 0;
}
#include<conio.h>
#include<iostream.h>
#include<ctype.h>
main()
{
FILE *SariSariStore;
int item_id;
char answer;
char item_name[50];
SariSariStore = fopen("c:\\myfolder\\sarisari.txt","a+");
do {
clrscr();
cout<<"Enter Item no.: ";
cin>>item_id;
cout<<"Enter Item name: ";
fflush(stdin);
gets(item_name);
cout<<"Do you want to save? Y/N: ";
cin>>answer;
if(toupper(answer)=='Y')
fprintf(SariSariStore,"%i %s \n", item_id, item_name);
}while(toupper(answer)!='N');
fclose(SariSariStore);
return 0;
}
// THIS IS THE CODE FOR DISPLAY
#include <stdio.h>
#include<iostream.h>
#include<conio.h>
main( )
{
FILE *SariSariStore;
char c;
clrscr();
SariSariStore = fopen("sarisari.txt", "r");
if (SariSariStore == NULL) printf("File doesn't exist\n");
else {
do {
c = getc(SariSariStore); // get one character from the file
putcharŠ; // display it on the monitor
} while (c != EOF); // repeat until EOF (end of file)
}
fclose(SariSariStore);
getch();
return 0;
}
//THIS IS THE CODE FOR SEARCH
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <iostream.h>
#include <ctype.h>
main()
{
FILE *SariSariStore;
int found = 0;
char name[100], target[100], name1[100];
clrscr();
SariSariStore = fopen("c:\\sarisari.txt" ,"r");
if(SariSariStore==NULL)
printf("File not found");
else
printf("Enter Name to Search : ");
fflush(stdin);
gets(target);
do
{
fscanf(SariSariStore,"%s %s",&name,&name1);
if(strcmp(name,target)==0)
{
found =1;
}
}while(!feof(SariSariStore) && found == 0);
if(found==1)
{
printf("Name: %s %s",name,name1);
}
else
printf("Not Found");
fclose(SariSariStore);
getch();
return 0;
}