473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to search for matching names in the dat file?

4
I m doing my work and the question was being asked.User of the program suppose to type in the product name,and the program will search through the dat files created earlier on and find matching result.For example,user type in 1Gb ram,then the price of the ram will be shown.How am i suppose to do this?thanks in advance for any help.I m in C language.
Dec 19 '07 #1
6 2470
gpraghuram
1,275 Expert 1GB
I m doing my work and the question was being asked.User of the program suppose to type in the product name,and the program will search through the dat files created earlier on and find matching result.For example,user type in 1Gb ram,then the price of the ram will be shown.How am i suppose to do this?thanks in advance for any help.I m in C language.


What have you done on this or you have written any code for this.
Please write your code first and come back here with the problems you face and we can help you.
Thanks
Raghuram
Dec 19 '07 #2
m1m11
4
What have you done on this or you have written any code for this.
Please write your code first and come back here with the problems you face and we can help you.
Thanks
Raghuram
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. void main () {
  3.     FILE*pr=fopen("price.dat","r");
  4.    double cost;
  5.    char name[20],nm[20];
  6.       while (fscanf(pr,"%s%lf",&name,&cost) !=EOF)
  7.    {printf("Item required:");
  8.     scanf("%s",&nm);
  9.  
this is how far i can get...so how am i suppose to do so that the program search in the dat file and give me the corresponding price?thanks
Dec 19 '07 #3
gpraghuram
1,275 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. void main () {
  3.     FILE*pr=fopen("price.dat","r");
  4.    double cost;
  5.    char name[20],nm[20];
  6.       while (fscanf(pr,"%s%lf",&name,&cost) !=EOF)
  7.    {printf("Item required:");
  8.     scanf("%s",&nm);
  9.  
this is how far i can get...so how am i suppose to do so that the program search in the dat file and give me the corresponding price?thanks
Hi,
Thle logic shuld be like this
1)Get the pattern to search for
2)Open the file
3)Start reading the file
3.1)if you know the pattern then get the name with which you need to compare
3.2)Do this till you reach the end of file or you get the pattern
4)Print the result and exit

Raghuram
Dec 19 '07 #4
m1m11
4
Hi,
Thle logic shuld be like this
1)Get the pattern to search for
2)Open the file
3)Start reading the file
3.1)if you know the pattern then get the name with which you need to compare
3.2)Do this till you reach the end of file or you get the pattern
4)Print the result and exit

Raghuram
thanks.that is what i was thinking too..my data pattern goes like this
ram 54
harddisk 159
can you please give me more hints on how to write the code?i tried to use if statement..but don seems to work.
Dec 19 '07 #5
gpraghuram
1,275 Expert 1GB
thanks.that is what i was thinking too..my data pattern goes like this
ram 54
harddisk 159
can you please give me more hints on how to write the code?i tried to use if statement..but don seems to work.
Check this
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main ()
  5. {
  6.    FILE*pr=fopen("price.dat","r");
  7.    double cost;
  8.    char name[20],nm[20];
  9.    scanf("%s",&nm);
  10.    if(pr != NULL)
  11.    {
  12.        while (fscanf(pr,"%s%lf",&name,&cost) !=EOF)
  13.        {
  14.            if(strcmp(name,nm) == 0)
  15.            {
  16.                /*u have got the required item*/
  17.                printf("iiiiii\n");
  18.                break;
  19.            }
  20.            printf("Item required:");
  21.        }
  22.        fclose(pr);
  23.      }
  24.  
  25. }
  26.  
I think you can build ur code from here.
Thanks
Raghuram
Dec 19 '07 #6
m1m11
4
Check this
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main ()
  5. {
  6.    FILE*pr=fopen("price.dat","r");
  7.    double cost;
  8.    char name[20],nm[20];
  9.    scanf("%s",&nm);
  10.    if(pr != NULL)
  11.    {
  12.        while (fscanf(pr,"%s%lf",&name,&cost) !=EOF)
  13.        {
  14.            if(strcmp(name,nm) == 0)
  15.            {
  16.                /*u have got the required item*/
  17.                printf("iiiiii\n");
  18.                break;
  19.            }
  20.            printf("Item required:");
  21.        }
  22.        fclose(pr);
  23.      }
  24.  
  25. }
  26.  
I think you can build ur code from here.
Thanks
Raghuram
thanks a lot man...i will try it..but..not all the command here are what i have learnt..but still..thanks a lot..
Dec 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
0
by: mm | last post by:
Can someone with Win 2K please help me here. Best yet, can some MVP duplicate it and report it to MS. I can't find any reference to this issue on the Web, or in MS Knowledge Base. I have been...
6
by: DC | last post by:
Hi, I am programming a search catalogue with 200000 items (and growing). I am currently using the SQL Server 2000 fulltext engine for this task but it does not fit the requirements anymore. ...
1
by: Prem | last post by:
Hi, I need to search a particular directory for all the files that do not have any extension and have a specific naming convension. The first 3 characters of the file name are alpha and the rest...
4
by: RoadRunner | last post by:
Hi, I have a question. I am asked to produce a global search of a given corporate name, in more that one database. Each database has different table names and different field names in the tables....
0
by: Chung Leong | last post by:
Here's a short tutorial on how to the OLE-DB extension to access Windows Indexing Service. Impress your office-mates with a powerful full-text search feature on your intranet. It's easier than you...
14
by: henrik.sorensen | last post by:
Hi List, I am looking for a way to do a case insensitive search for file names. Anybody have some hints ? thanks Henrik pl1gcc.sourceforge.net
1
by: Peter v.d. Berger | last post by:
Hello, I'm working on a script that can place results of soccergames from different seasons in a row, to see the history of the game. I've gattered a lot of scores from different websites on a...
16
by: Computer geek | last post by:
Hello, I am new to VB.NET and programming in general. I have taught myself a lot of the basics with vb.net but am still quite the novice. I am working on a little application now and I need some...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.