Jump to content


Photo

Simple add, search, display functions


  • Please log in to reply
2 replies to this topic

#1 makoy63

makoy63

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 12 August 2008 - 07:42 AM

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:

#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;
 
 }

Edited by makoy63, 14 August 2008 - 07:24 AM.


#2 JoeyMagz

JoeyMagz

    Young Padawan

  • Members
  • Pip
  • 79 posts
  • Gender:Male
  • Location:Chesapeake, VA

Posted 13 August 2008 - 09:56 PM

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.

#3 makoy63

makoy63

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 14 August 2008 - 07:25 AM

post edited. thanks in advance. any help would be appreciated.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users