473,804 Members | 3,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating Data in C programming

Does anyone know how to perform data validation in C? I have searched
google for every possible result, and I either end up with data
validation for C++ or nothing at all. I have also searched websites
such as planet-source-code.com, but my search has been in vain.

Can someone please help me out. Or at least, point me in the right
direction?

Thank you very much. :)

Aug 5 '06 #1
21 4518
MQ

gurdz wrote:
Does anyone know how to perform data validation in C? I have searched
google for every possible result, and I either end up with data
validation for C++ or nothing at all. I have also searched websites
such as planet-source-code.com, but my search has been in vain.

Can someone please help me out. Or at least, point me in the right
direction?

Thank you very much. :)
Data validation is a generic programming technique that is language
independant. It is just the process of checking that data input to
your program is within the range of expected values, etc. If you are
expecting a number between 1 and 10, check that it is a number between
1 and 10 before using it. What is so hard about that? Unless I am not
understanding your question...

Aug 5 '06 #2
gurdz wrote:
Does anyone know how to perform data validation in C?
Yes, you look at the data and see if it matches your validation rules.
I have searched
google for every possible result, and I either end up with data
validation for C++ or nothing at all. I have also searched websites
such as planet-source-code.com, but my search has been in vain.

Can someone please help me out. Or at least, point me in the right
direction?
It really depends on what the data you are trying to validate is, what
the rules are, and where the data is coming from. There is no one size
fits all solution.
--
Flash Gordon
Still sigless on this computer.
Aug 5 '06 #3
Flash Gordon said:

<snip>
>
It really depends on what the data you are trying to validate is, what
the rules are, and where the data is coming from. There is no one size
fits all solution.
Yes, there is.

The following fragment is taken from the source code used by a major UK
bank, the identity of which will remain anonymous (to protect the guilty).
It was spotted during Y2K work in the late 1990s:

if(d != 6)
{
d = 6;
}

Viola! All numbers are 6, even if they aren't. QED.

How we laughed! We laughed and laughed and laughed, until we stopped.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 5 '06 #4

Richard Heathfield wrote:
The following fragment is taken from the source code used by a major UK
bank, the identity of which will remain anonymous (to protect the guilty).
It was spotted during Y2K work in the late 1990s:

if(d != 6)
{
d = 6;
}

Viola! All numbers are 6, even if they aren't. QED.

How we laughed! We laughed and laughed and laughed, until we stopped.
It is possible that there are occasions for using it.

Aug 5 '06 #5
MQ

Richard Heathfield wrote:
The following fragment is taken from the source code used by a major UK
bank, the identity of which will remain anonymous (to protect the guilty).
It was spotted during Y2K work in the late 1990s:

if(d != 6)
{
d = 6;
}
I don't think that it is any secret that banks have their own brand of
logic, that seems to err in their favour

Aug 5 '06 #6
On 2006-08-05, lovecreatesbeau ty <lo************ ***@gmail.comwr ote:
>
Richard Heathfield wrote:
>The following fragment is taken from the source code used by a major UK
bank, the identity of which will remain anonymous (to protect the guilty).
It was spotted during Y2K work in the late 1990s:

if(d != 6)
{
d = 6;
}

Viola! All numbers are 6, even if they aren't. QED.

How we laughed! We laughed and laughed and laughed, until we stopped.

It is possible that there are occasions for using it.
....where typing `d = 6' or even just `6' wouldn't suffice?

--
Andrew Poelstra <http://www.wpsoftware. net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
Aug 5 '06 #7
"Andrew Poelstra" <ap*******@fals e.sitewrote
On 2006-08-05, lovecreatesbeau ty <lo************ ***@gmail.comwr ote:
>>
Richard Heathfield wrote:
>>The following fragment is taken from the source code used by a major UK
bank, the identity of which will remain anonymous (to protect the
guilty).
It was spotted during Y2K work in the late 1990s:

if(d != 6)
{
d = 6;
}

Viola! All numbers are 6, even if they aren't. QED.

How we laughed! We laughed and laughed and laughed, until we stopped.

It is possible that there are occasions for using it.

...where typing `d = 6' or even just `6' wouldn't suffice?
if(d != 6)
{
fprintf(stderr, "somethign fishy here\n");
d = 6;
}

if(d != 6)
{
// fprintf(stderr, "somethign fishy here\n");
d = 6;
}

Three months later, another compiler
Warning, non-standard comment line 3456

if((d != 6)
{
d = 6;
}

--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.

Aug 5 '06 #8
On Sat, 05 Aug 2006 10:18:58 +0000, Richard Heathfield
<in*****@invali d.invalidwrote:
>Flash Gordon said:

<snip>
>>
It really depends on what the data you are trying to validate is, what
the rules are, and where the data is coming from. There is no one size
fits all solution.

Yes, there is.

The following fragment is taken from the source code used by a major UK
bank, the identity of which will remain anonymous (to protect the guilty).
It was spotted during Y2K work in the late 1990s:

if(d != 6)
{
d = 6;
}

Viola! All numbers are 6, even if they aren't. QED.

How we laughed! We laughed and laughed and laughed, until we stopped.
<gLooks like a left-over debug statement. A place to set a
breakpoint.

--
Al Balmer
Sun City, AZ
Aug 5 '06 #9
Andrew Poelstra wrote:
On 2006-08-05, lovecreatesbeau ty <lo************ ***@gmail.comwr ote:
>>Richard Heathfield wrote:
>>>The following fragment is taken from the source code used by a major UK
bank, the identity of which will remain anonymous (to protect the guilty).
It was spotted during Y2K work in the late 1990s:

if(d != 6)
{
d = 6;
}

Viola! All numbers are 6, even if they aren't. QED.

How we laughed! We laughed and laughed and laughed, until we stopped.

It is possible that there are occasions for using it.


...where typing `d = 6' or even just `6' wouldn't suffice?
It's an optimization. On a virtual memory system, it avoids
setting the "dirty" bit for a memory page unnecessarily, thereby
avoiding the (potential) expense of a page-out operation later,
or at least not incurring the expense for no good purpose.

(Hmmm: That variable name, `d'. Was the author, by any
chance, named Reginald?)

--
Eric Sosman
es*****@acm-dot-org.invalid

Aug 5 '06 #10

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

Similar topics

6
2430
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting is not absolutely wonderful. So what I want to do is to validate it before I upload it. When I try and do this I get MILLIONS of errors (well lots) complaining about elements like ROOT which are part of the
1
4248
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end of the post. I am using VS.net 2003, .Net 1.1, Win2k Server I have a simple schema and a simple XML document.
0
2441
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
5
9346
by: norton | last post by:
Hi All, I am writing a simple win form which contains a button, when user click the button i want to validate all the other textbox and see if there is anything goes wrong may i know how can i trigger the validating event for all text box? thx and regard,s
4
2484
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form, but not when I try to switch form one Mdi form to the other. I tried to add code to MdiForm1's Deactivate event: Private Sub MidForm1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate Dim TempE As...
5
4820
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of validation.. Is there any funciton in vb.net for this? or any other way?? Waiting for ur replies...
3
2800
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
232
13383
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
8
4133
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has prevailed it just is :) My problem is this im trying to validate the contents of a textbox (it has to be a normal textbox) and on a c# winforms and i am calling the textbox validating
0
9706
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
10583
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
10337
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...
0
10082
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
9160
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
7622
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...
1
4301
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
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
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.