473,394 Members | 1,875 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.

pattern matching program problem

hi friends this is arun from coimbatore.i had written one program for pattern matching.That is ,the user have one file and after run his c program he pass some text command line, if the text is found in file the line number will be print.but my program checks only first two lines.it will not check other lines.i am trying to find out the prob.plz anybody help me to find wat wrong in my program.
thanking u.
the program is:

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. main(int x,char *j[])
  5. {
  6. int g,h,z=1;
  7. char ch,c[30]=" ",d[30]=" ",a[30]=" ";
  8. int n,i=0,line=0;
  9. FILE *f;
  10. printf("*****************FILE NAME IS:%s\n",j[1]);
  11. f=fopen(j[1],"r");
  12. if(f!=NULL)
  13. printf("*****************FILE OPENED****************\n");
  14. for(n=2;n<x;n++)
  15. {
  16. strcat(c,j[n]);
  17. if(n!=x-1)
  18. strcat(c," ");
  19. }
  20. strcpy(a,c);
  21. for(g=0,h=1;a[g]!='\0';g++,h++)
  22. a[g]=a[h];
  23. a[g]='\0';
  24. printf("******************SEARCH TEXT IS:%s\n",a);
  25. while((z=feof(f))==0)
  26. {
  27. fseek(f,0,1);
  28. while((ch=fgetc(f))!='\n')
  29. i++;
  30. i=i+2;
  31. line++;
  32. fseek(f,-i,1);
  33. fgets(d,i,f);
  34. if((strstr(d,a))!=NULL)
  35. {
  36. printf("******************LINE NO IS=>%d  :%s\n",line,d);
  37. }
  38. else
  39. {
  40. printf("*****************LINE NO IS=>%d\t***********NOT FOUND\n",line);
  41. }
  42. i=0;
  43. }
  44. }
Jan 19 '08 #1
1 2584
Ganon11
3,652 Expert 2GB
I'm sorry that I can't give you an answer to your immediate question, but I suggest you take the time to learn proper indenting. As it is right now, your code is a horrible mess that's hard to decipher. Taking 5 minutes or so to go through it and indent it properly - two or three spaces per block a statement is embedded in - will make your life MUCH easier when you go back to edit it. Better yet, do it while you are coding.
Jan 19 '08 #2

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

Similar topics

8
by: gsv2com | last post by:
One of my weaknesses has always been pattern matching. Something I definitely need to study up on and maybe you guys can give me a pointer here. I'm looking to remove all of this code and just...
176
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
5
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
9
by: Jim Lewis | last post by:
Anyone have experience with string pattern matching? I need a fast way to match variables to strings. Example: string - variables ============ abcaaab - xyz abca - xy eeabcac - vxw x...
8
by: 116Rohan | last post by:
I came across a question in one of the Computing olympiad regarding string pattern matching. Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the...
2
by: Ole Nielsby | last post by:
First, bear with my xpost. This goes to comp.lang.c++ comp.lang.functional with follow-up to comp.lang.c++ - I want to discuss an aspect of using C++ to implement a functional language, and...
1
by: VanKha | last post by:
I write this program for pattern-matching,but it gives wrong result: #include<iostream> #include<conio.h> #include<string.h> using namespace std; main() { char text,pat;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.