473,698 Members | 2,346 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 2218
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
2038
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
17305
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
2271
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
10989
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
1088
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
14642
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
1807
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
3134
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
2667
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
8676
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
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7734
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...
1
6524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
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
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.