473,413 Members | 1,755 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,413 software developers and data experts.

error detection

I'd like to ask,if i have some equations in a text file such as:
1) 2+45-43
2) 28+50-3
3) 12++36
i need a function that detects the error (eq. 3) when reading the file.is there any possible way to do this in c????
Feb 19 '10 #1
3 1883
donbock
2,426 Expert 2GB
Certainly this kind of syntax checking can be done in C. However, you need to carefully and completely specify the grammer.

For example, the unary minus (negation) can cause a lot of confusion. Do you want these expressions to be legal?
12+-36 (12 plus -36)
4*-8 (4 times -8)

Grammar checking can involve pretty complicated C code. You might want to look at tools made specifically for that job (such as lex or flex) or a language that reduces the edit/build/test/fix cycle time (such as perl).
Feb 19 '10 #2
the first expression is not legal,it should be:
12-36
this is what came to my mind,i know it's not efficient because it doesn't take (,) into consideration,i haven't heard of (lex and flex) before,how can i use them for this purpose??
void finderror(FILE *in,char line[])
{
int i;
int max=countequ(line,in);

for(i=0;i<max;i++)
{read(line,in);
if ((line[i]=='+' &&line[i+1]=='+') || (line[i]=='+' &&line[i+1]=='-') || (line[i]=='+' &&line[i+1]=='*') || (line[i]=='+' &&line[i+1]=='/') || (line[i]=='*' &&line[i+1]=='*') |(line[i]=='*' &&line[i+1]=='+') || (line[i]=='*' &&line[i+1]=='-') || (line[i]=='*' &&line[i+1]=='/')|| (line[i]=='-' &&line[i+1]=='-') || (line[i]=='-' &&line[i+1]=='+') || (line[i]=='-' &&line[i+1]=='*') || (line[i]=='-' &&line[i+1]=='/') || (line[i]=='/' &&line[i+1]=='/') || (line[i]=='/' &&line[i+1]=='+') || (line[i]=='/' &&line[i+1]=='-') || (line[i]=='/' &&line[i+1]=='*'))
printf("ERROR IN LINE : %d",i+1);
else
printf("ALL SUCCESSFUL");
}
}
Feb 20 '10 #3
donbock
2,426 Expert 2GB
Look here for details on lex and flex. lex was the original program; flex is a free (but non-Gnu) version.
Feb 20 '10 #4

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

Similar topics

0
by: Cherrish Vaidiyan | last post by:
sir, The following are the steps that i followed in setting up standby database on Red hat Linux 9. i am using Oracle 9i. i have followed the steps in this site : ...
2
by: andy johnson | last post by:
I made the mistake of "upgrading" to IE6.0 on my windoze 98 laptop. I really wish bill gates would die in a horribly painful accident. Anyway, after much grief, I downloaded Opera and saw true...
2
by: Simon | last post by:
I have recently set up a server certificate on a web site. Under certain conditions I need to change the color of a html span element. I do this using the following javascript function called from...
3
by: news.onetel.net.uk | last post by:
I and my friend Karl have spent literally all day trying to find out what is causing my error but we are zapped of any further functionality :) I have a form that adds news records. You select...
7
by: debugger | last post by:
hello, Question, on page load, I populate an existing drop down with createElement and appendChild. It works fine so far. BUT I want to automatically select some option from this populated drop...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
0
by: JohnQ | last post by:
(The thread "Error Handling Idioms" prompted this post. I meant to post it at the top level, but it got posted as a reply. So here it is again!) An attempt at common defintions: fault: the...
2
by: coolsmaster | last post by:
When I put my code through different inputs, one form of input results in a problem. when I enter: updatename 123456789 10 f9 the expected output is "Error: 10 is out of the range 0-4" ...
3
by: harshadanarvekar | last post by:
Hi Everyone, Here is a part of javascript code that works well in FF2 but shows above error in IE6 and error "missing name after . operator" in NS8 function PopUp(idf,stepX,stepY,speed){
0
by: origami.takarana | last post by:
Intrusion Detection Strategies ----------------------------------- Until now, we’ve primarily discussed monitoring in how it relates to intrusion detection, but there’s more to an overall...
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?
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
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
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
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...

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.