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

Character conversion, Can = or != be converted from string?

Hi again to everyone!

First of all i would like to thank all the people in this forum for
their help, i've gone far in my project and i have to thank you for
that! I hope i can repay all the help given.

My question is this, can i make a converstion from a string to an = or
!= Operators?

I have a client program that sends information to a suposed "sql
server" that processes the requests. Both Create and Insert are easy
but Update and Select use = or != operands. Of course i can do a
comparison of the caracters inserted with if and elses but the
eficiency of the program would go sky high if a direct comparison could
be made. For example:

UPDATE Table_name SET colum_name = new_value WHERE colum_name =
old_value

or

SELECT column FROM table WHERE column operator value

My question applies better to the Select command has with the Update
command this question is also easy to solve.
Can this be done? Thanks in advance for any help.

Best Regards

Pedro Pinto

Dec 5 '06 #1
4 1510
Pedro Pinto wrote:
Hi again to everyone!

First of all i would like to thank all the people in this forum for
their help, i've gone far in my project and i have to thank you for
that! I hope i can repay all the help given.

My question is this, can i make a converstion from a string to an = or
!= Operators?
<snip>

Your question is not very clear, but if you're asking whether you can
directly compare two strings with ==, (not =), or !=, then no, C
doesn't have such a feature. You can however use a library function to
compare two or more strings. The standard library functions, strcmp()
and strncmp() do exactly this. Note that they're case sensitive. If you
want to ignore case, convert the strings to a common case via tolower()
or toupper() and then compare.

Dec 5 '06 #2
santosh wrote:
Pedro Pinto wrote:
<snip>
My question is this, can i make a converstion from a string to an = or
!= Operators?
<snip>

Your question is not very clear, but if you're asking whether you can
directly compare two strings with ==, (not =), or !=, then no, [ ... ]
There're also memcmp() and strcoll().

Dec 5 '06 #3
"Pedro Pinto" <ku*****@gmail.comwrites:
My question is this, can i make a converstion from a string to an = or
!= Operators?

I have a client program that sends information to a suposed "sql
server" that processes the requests. Both Create and Insert are easy
but Update and Select use = or != operands. Of course i can do a
comparison of the caracters inserted with if and elses but the
eficiency of the program would go sky high if a direct comparison could
be made. For example:
It's really not clear to me what you're trying to do. It's not
even clear whether you're trying to write the client or the
server program. Can you give some more details?
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Dec 5 '06 #4
Pedro Pinto wrote:
I have a client program that sends information to a suposed "sql
server" that processes the requests. Both Create and Insert are easy
but Update and Select use = or != operands. Of course i can do a
comparison of the caracters inserted with if and elses but the
eficiency of the program would go sky high if a direct comparison could
be made. For example:
There's no way to automatically execute code found in a string. C code
is compiled by a compiler into machine code. Once your program is
running, the compiler is no longer available. If you need to evaluate
arbitrary expressions supplied at run time, you must write your own
interpreter.
UPDATE Table_name SET colum_name = new_value WHERE colum_name =
old_value

or

SELECT column FROM table WHERE column operator value
You want to write a SQL server? You want to write a program that
understands and executes UPDATE and SELECT commands?

You need to parse the command into an array or list of tokens:

{"SELECT", "column", "FROM", "table",
"WHERE", "column", "operator", "value"}

Then identify the keywords, and get the variable data (column name, the
table name, etc). You will need to write code that searches through the
data. The simplest way would be to go through each record in your
database and match it against the given conditions.

Here's some pseudocode. You need to implement the functions parse,
get_value, and add_result.

parse("SELECT name FROM classmates WHERE sex = female",
select_column,
select_table,
where_column,
where_operator,
where_value);

/* After tokenisation and parsing now
select_column is "name",
select_table is "classmates",
where_column is "sex",
where_operator is "=",
and where_value is "female"
*/

for(row = 0; row < num_rows; row++)
{
const char *data_value = get_value(row, where_column);
if(!strcmp(where_operator, "=")
{
if(!strcmp(where_value, data_value)) add_result(row);
}
else if(!strcmp(where_operator, "!=")
{
if(strcmp(where_value, data_value)) add_result(row);
}
else
{
fprintf(stderr, "Unrecognised operator %s\n", where_operator);
}
}

--
Simon.
Dec 6 '06 #5

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

Similar topics

0
by: Tumurbaatar S. | last post by:
Hi, I'm running MySQL 3.23.55 on WinXP and have some problem using non latin charset. I've added these 2 lines under group of my.ini: character-sets-dir = c:/mysql/share/charsets/...
5
by: Stefan Krah | last post by:
Hello, I am currently writing code where it is convenient to convert char to int . The conversion function relies on a character set with contiguous alphabets. int set_mesg(Key *key, char...
5
by: Kasper Hansen | last post by:
I need to search through a binary file to find a specific string and then replace it with another string. However the System.Text.Encoding.ASCII.GetString method i originally used seems to do some...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
5
by: Jayson Davis | last post by:
Say I have a string read from a configuration file. searchfor <tab> Needle\n\n Where I want to search for the word "Needle" with two linefeeds. Now when I read it from the file, it hasn't...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
11
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h>...
6
by: Peter Lee | last post by:
what's the correct behaver about the following code ? ( C++ standard ) I got a very strange result.... class MyClass { public: MyClass(const char* p) { printf("ctor p=%s\n", p);
6
by: ssetz | last post by:
Hello, For work, I need to write a password filter. The problem is that my C+ + experience is only some practice in school, 10 years ago. I now develop in C# which is completely different to me....
7
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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
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...
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...

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.