473,395 Members | 1,762 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.

How to implement case insensitive fncs?

Implement AccessIgnoreCase() to count the number of stations from the head to a destination using linked list.
for e.g.
PoLam->HangHau->TseungKwanO->TiuKengLeng->YauTong->QuarryBay->NorthPoint->NIL

Implement Access() which is case sensitive. However, it crashes when input does not match the string. How can I resolve this and how can I write a AccessIgnoreCase() which is case insensitive?


int List::Access(string str)
{
if (m_Head == NULL)
return -1;
else
{
if (m_Head->str == str)
return 0;
else
{
int counter = 0;
Node* current;
current = m_Head;

while (current!= NULL)
{
counter++;

if (current->ptrNext->str == str)
return counter;
else
current = current->ptrNext;
}
if (current == NULL)
return counter;
}
return -1;
}
}
Mar 16 '10 #1
1 1520
jkmyoung
2,057 Expert 2GB
Here's your problem:
if (current->ptrNext->str == str)
All you know is current != null.
You don't know if current->ptrNext ?= null, which it does when the program crashes.
Change it to
if (current->str == str)
and adjust your counter accordingly, eg maybe put the increment at the end of the loop.

Use a string function to convert both strings to lower case. eg:
http://www.dreamincode.net/code/snippet39.htm
Mar 16 '10 #2

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

Similar topics

32
by: Elliot Temple | last post by:
Hi I have two questions. Could someone explain to me why Python is case sensitive? I find that annoying. Also, why aren't there multiline comments? Would adding them cause a problem of some...
5
by: Madjid Nasiri | last post by:
Hi, I am basic in oracle. My Old programs write with Delphi and Databases: Access, Paradox, MySQL, Microsoft SQL. I write my code (SQL code) case-insensitivae, but now i need use oracle database....
12
by: Relaxin | last post by:
Is there a way to make Postgresql case-INSENSITIVE? Thanks
2
by: Tom | last post by:
Hi, Our development team is adding DB2 8.1 compatibility to our existing application which currently supports SQLServer 2000. Our code is written to take advantage of SQLServer's ability to ...
14
by: Christian Sell | last post by:
Hello, I am running into a problem with PGs case sensitivity with regard to column and table names. I am using program components that require the object names returned from database metadata...
13
by: Tom Anderson | last post by:
Afternoon all, MacOS X seems to have some heretical ideas about the value of case in paths - it seems to believe that it doesn't exist, more or less, so "touch foo FOO" touches just one file,...
1
by: benhoefer | last post by:
I have been searching around and have not been able to find any info on this. I have a unique situation where I need a case sensitive map: std::map<string, intimap; I need to be able to run a...
4
by: bb | last post by:
Hi, void fun(const std::map<std::string,int>& m1) { // How to make a case insensitive search of this map without making a copy? } cheers.
6
by: Derik | last post by:
Okay, I THINK this is a PHP question... I've been mucking with PHP for awhile now, but just recently I've been poking at some ajax stuff, and I ran into something confusing; my Queries were...
0
by: Ethan Furman | last post by:
Maric Michaud wrote: Actually, the OP said: -- So you're saying to ensure that stage_map's keys are initially -- lower-case to begin with? Well, I can't do this either since the -- *case of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...
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,...

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.