473,466 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Search input string

hey..i ma newbie to c programming...its just my 3rd program..so i
wanna know a code in which input string can be matched with strings in
another opened file....!!

Apr 26 '07 #1
3 1983
lucky_therock wrote:
hey..i ma newbie to c programming...its just my 3rd program..so i
wanna know a code in which input string can be matched with strings in
another opened file....!!
So, what do you have so far?

- Determine your specifications (exact string match? partial matches?
find all matches or first one wins?)
- Sketch out some pseudo-code to work out your algorithm.
- Iteratively develop the code.

e.g., my naive approach:

- Process the args verbatim (spaces significant), converting to same
case (caring about locale) if we don't care about case and make this our
constant search string. Handle errors.
- Open the external file, and read in contents as text, forming what we
get as an array of strings (convert to same case [again, locale issues]
if necessary). Handle error on open, on read and on memory allocation(s).
- Iterate through the strings, matching with our search string. On a
match, do something (save something or set a flag or whatever). Repeat
until list exhausted, if necessary.

The devil is in the details, but the actual logic is pretty simple. Of
course, there is all sorts of room for improvement on what I've
described here.
--
clvrmnky

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Apr 26 '07 #2
On 26 Apr 2007 11:37:58 -0700, lucky_therock
<lu***************@gmail.comwrote:
>hey..i ma newbie to c programming...its just my 3rd program..so i
wanna know a code in which input string can be matched with strings in
another opened file....!!
Consider using the strcmp() function. From the current C standard:

7.21.4.2 The strcmp function

Synopsis
include <string.h>
int strcmp(const char *s1, const char *s2);

Description
The strcmp function compares the string pointed to by s1 to the string
pointed to by s2.

Returns
The strcmp function returns an integer greater than, equal to, or less
than zero, accordingly as the string pointed to by s1 is greater than,
equal to, or less than the string. The contents of ‘‘holes’’ used as
padding for purposes of alignment within structure objects are
indeterminate. Strings shorter than their allocated space and unions
may also cause problems in comparison.

Regards
--
jay
Apr 27 '07 #3
On 27 Apr, 07:14, jaysome <jays...@hotmail.comwrote:
On 26 Apr 2007 11:37:58 -0700, lucky_therock
<lucky.therock2...@gmail.comwrote:
hey..i ma newbie to c programming...its just my 3rd program..so i
wanna know a code in which input string can be matched with strings in
another opened file....!!
Consider posting in standard English. It makes your posts easier to
read.

Consider using the strcmp() function. From the current C standard:

7.21.4.2 The strcmp function

Synopsis
include <string.h>
int strcmp(const char *s1, const char *s2);

Description
The strcmp function compares the string pointed to by s1 to the string
pointed to by s2.

Returns
The strcmp function returns an integer greater than, equal to, or less
than zero, accordingly as the string pointed to by s1 is greater than,
equal to, or less than the string. The contents of ''holes'' used as
padding for purposes of alignment within structure objects are
indeterminate. Strings shorter than their allocated space and unions
may also cause problems in comparison.
depending what the OP is trying to do, strstr() might be better
--
Nick Keighley
Apr 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Greg | last post by:
I have a page that searches a database by a repairman's name and by a date range. It pulls info by the repairman's name but pulls all info in the database regardless of the date. Below is the code...
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...
1
by: Dave Townsend | last post by:
Hi, Can anybody help me with the following piece of code? The purpose behind the code is to parse HTML files, strip out the tags and return the text between tags. This is part of a larger...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
3
by: Russell | last post by:
Hey, ok i have numerous tables to search through for a 'site search'. some of the searchble fields have html embeded within so after some quick referencing, saw I can use the regExp function...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
41
by: nik707 | last post by:
Hello all, First of all my name is Shan and I am currently learning and also designing a database in Access. Your forum users seems to be very helpful and experts in this matter so I thought I...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.