Help - Search - Members - Calendar
Full Version: Simple add, search, display functions
Pixel2Life Forum > Help Section > Desktop Programming
makoy63
hi guys.

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;

}
JoeyMagz
could you please put that code into the code tags. Also, indent the code properly so I can actually read what I'm looking at. =/ lol sorry if that sounded rude, I just can't tell if you're indenting code properly, putting {,} and ; where they need to be, etc.
makoy63
post edited. thanks in advance. any help would be appreciated.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.