473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WILDCARD: output all a* by searching a text file

/*program to search a* in a text file & write output in a file.*
indicated any character. IT IS WORKING BUT HOW TO GENERALISE IT FOR A
LONG STRING
LIKE umesh*** OR Suppose I want to find all words in a text file which
starts with 'a'
and ends with 'z' i.e a*z
where * denotes a string of characters. How can I do it? */

#include<stdio. h>
#include<stdlib .h>
int main(void)
{
FILE *f,*fp;
f=fopen("c:/1.txt","r");
if(f==NULL) { puts("Error opening file");exit(0); }
fp=fopen("c:/2.txt","w");
char c,ch;
while((c=getc(f ))!=EOF && (ch=getc(f))!=E OF )
{
if(c=='a'&& ch!=' ')
fprintf(fp,"%c% c\n",c,ch);

}
fclose(f);
fclose(fp);
return 0;

}
/* INPUT
abc
abc
abd
ap
OUTPUT
ab
ab
ab
ap
*/

May 18 '07 #1
4 2221
ume$h wrote:
/*program to search a* in a text file & write output in a file.*
indicated any character. IT IS WORKING BUT HOW TO GENERALISE IT FOR A
LONG STRING
LIKE umesh*** OR Suppose I want to find all words in a text file which
starts with 'a'
and ends with 'z' i.e a*z
where * denotes a string of characters. How can I do it? */
Read up on regular expressions and find a regex library. Boost.Regex is
a good place to start.

--
Ian Collins.
May 18 '07 #2
/*thx,this one works but how to prevent it from giving duplicate
results? e.g. i don't want 'ab' more than once as output.*/

#include<stdio. h>
#include<stdlib .h>
int main(void)
{
FILE *f,*fp;
f=fopen("c:/1.txt","r");
if(f==NULL) { puts("Error opening file");exit(0); }
fp=fopen("c:/2.txt","w");
char c[3];
while((c[0]=getc(f))!=EOF)
if(c[0]=='a' && (c[1]=getc(f))!=EOF && c[1]!=' ')
{
c[2]='\0';
fprintf(fp,"%s\ n",c);
}
fclose(f);
fclose(fp);
return 0;
}

May 18 '07 #3
ume$h wrote:
/*program to search a* in a text file & write output in a file.*
I see you still ignore all the advice you got on comp.lang.c, and you
have morphed your ID. I smell troll now.

*plonk* again


Brian
May 18 '07 #4
ume$h wrote:
/*thx,this one works but how to prevent it from giving duplicate
results? e.g. i don't want 'ab' more than once as output.*/
Retain context. Head advice. Confine trolling to one NG!

--
Ian Collins.
May 18 '07 #5

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

Similar topics

1
2044
by: Naveen M | last post by:
Hi, We have an asp.net app that uploads and downloads files files from an FTP server. It works this way. 1) Put a MyFile.request file on the server 2) server processes and returns MyFile.txt 3) My application looks for MyFile.txt and downloads. So far so good. The problem occurs if there is some error in processing in which case the server does not return a MyFile.txt but an error file called MyFile-MM-DD-YYYY-hh-
3
17308
by: Dan W | last post by:
Hi there. I am parsing a text file and as I parse each line I need to go out to two different directories and check to see if any files beginning with the string I just parsed exist. For example... if the first line in my text file is AS1501 then I need to check Dir1 and see if there are any files that begin with AS1501 then I need to go to Dir2 and check there also. I am trying to check using the following code... If...
3
2277
by: george.lengel | last post by:
Hello experts, I have been struggling for days to solve this problem and every suggestion I find via Google does not work for me. There is probably a solution out there that will do what I want, but I probably have not properly implemented the solutions I find. I am trying to make a page to allow personnel the ability to search our backend DB (which is Ingres 2.0) through a web interface. Ingres has a cgi program called ICE that can...
7
10991
by: eddie.holder | last post by:
Hi ladies and gents. I'm hoping anyone will be able to help me in a small access problem I am having. Let me try to explain: I have a form with textboxes which I use as criteria for a query. The form is used to allow my users to search for specific company names or if left blank, all the company names, so I built my criteria as follows: Like .. & chr(42) The form works ok if I am looking for a spesific company name, but when left...
0
1090
by: mfilpot | last post by:
I am working on a prime number generator for sschool, but I jsut can't seem to figure out how to write the contents of the variable MeSSage into a new text file, Can someone help me? the script is: '========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0 '
4
14646
by: =?Utf-8?B?UmljaA==?= | last post by:
Is it possible to use a wildcard like feature with Dataview.Find? Actually, I tried that but did not get any rows. Is there some wildcard like feature of the dataview or some other object that I could search/find rows in an ADO.Net dataTable? Or, am I stuck having to write a loop and search the loop for a substring of an expression?
21
1813
by: Umesh | last post by:
/*program to search a* in a text file & write output in a file.* indicated any character*/ #include<stdio.h> #include<stdlib.h> int main(void) { FILE *f,*fp; f=fopen("c:/1.txt","r"); if(f==NULL) { puts("Error opening file");exit(0);}
5
3137
by: Krustov | last post by:
I have the following list of image files . When searching the latest (numbered file) in this particular case its background_4.*** and its a .jpg file - but - the latest file in the list could also be a .gif file at times . zimages_background/background_1.jpg zimages_background/background_2.jpg zimages_background/background_3.gif zimages_background/background_4.jpg
0
2668
by: savage678 | last post by:
Hi Everyone, I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an access database using data connection. I have some code which will allow me to do it but i dont know how to change the code. Could someone please help me. I have added the code for you to. function MyQuery::OnClick(eventObj) { // Get the default SQL command for the form. var...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.