473,473 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help me!!!! how to compare array with the string?

3 New Member
Hi, i am currently doing a c++ program using Borland C++.
now i am facing a problem where i want to compare the keyword input from the user with the string that read from file.

this is a part of my codding that with error,

Expand|Select|Wrap|Line Numbers
  1. int position,py;
  2. char keyPrompt[100];
  3.  
  4. input.open("a.dat");
  5.   if (input.fail())
  6.  {
  7.   cout<<"Unable to open a file \n";
  8.   exit(1);
  9.   }//end if
  10.  
  11.   while(input>>alpha>>index)
  12.   {
  13.       Alpha[a].setkeyword(keyword);
  14.       Alpha[a].setindex(index);
  15.       a++;
  16.       }//end while
  17.     input.close();
  18.  
  19.  
  20.  
  21. cout<< enter keyword:";
  22. cin>>keyPrompt;
  23.  
  24. for(py=0; py<a; py++)
  25.      { //compare the first alphabet with the alphabet in file
  26.       if(strcmp(keyPrompt[0],Alpha[py].getkeyword())==0)
  27.  
  28.           {//alphabet match
  29.         position=py; //position in alpha array
  30.          break;
  31.        } //end if
i know that it is impossible to compare between keyPrompt[0] and string , but can anyone help me to search for another alternative that can use as similar as

Expand|Select|Wrap|Line Numbers
  1. strcmp(keyPrompt[0],Alpha[py],getkeyword())   
thanks!
Mar 16 '07 #1
5 2626
horace1
1,510 Recognized Expert Top Contributor
what does Alpha[py].getkeyword() return, a char * or a C++ string?

as you are working in C++ why not just use string type? e.g.
Alpha[py].getkeyword()
Mar 16 '07 #2
niceliang84
3 New Member
what does Alpha[py].getkeyword() return, a char * or a C++ string?

as you are working in C++ why not just use string type? e.g.
Alpha[py].getkeyword()


char * in my program.....

char *Database::getkeyword()
{
return Keyword;
}; //method getkeyword
Mar 16 '07 #3
horace1
1,510 Recognized Expert Top Contributor
char * in my program.....

char *Database::getkeyword()
{
return Keyword;
}; //method getkeyword
keyPrompt[0] is a char and strcpy expects its parameters to be char *
should the compare
Expand|Select|Wrap|Line Numbers
  1.       if(strcmp(keyPrompt[0],Alpha[py].getkeyword())==0)
  2.  
be
Expand|Select|Wrap|Line Numbers
  1.       if(strcmp(keyPrompt, Alpha[py].getkeyword())==0)
  2.  
Mar 16 '07 #4
niceliang84
3 New Member
keyPrompt[0] is a char and strcpy expects its parameters to be char *
should the compare
Expand|Select|Wrap|Line Numbers
  1.       if(strcmp(keyPrompt[0],Alpha[py].getkeyword())==0)
  2.  
be
Expand|Select|Wrap|Line Numbers
  1.       if(strcmp(keyPrompt, Alpha[py].getkeyword())==0)
  2.  

yap... i know that but i juz wana compare "keyPrompt[0]" with the string that i get from .dat file.....
for example:
if user Input Login
i just wana detect if the first word (keyPrompt[0]) is same as the data that i get from .dat file where the structure of .dat file is as below

a idx1
b idx2
c idx3
d idx4
.
.
l
.
z idx24

like tat... got any way to write this kind of programing code?
Mar 17 '07 #5
horace1
1,510 Recognized Expert Top Contributor
if you wish to check character by character you could try
Expand|Select|Wrap|Line Numbers
  1.      if(strcmp(keyPrompt[0], Alpha[py].getkeyword()[0])==0)
Mar 17 '07 #6

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

Similar topics

1
by: WroteForLuck | last post by:
I am trying to write a simple SQL statement which will take a string (startdate) in the format DDMMYYYY and compare it to a date stored in an Oracle database. My SQL is as follows: <% "select...
4
by: jarkkotv | last post by:
Hi everyone! I'm having a little problem when sorting the ArrayList and I was wondering if there is a .NET guru who can help me out :) I'm trying to sort ArrayList alphabetically in ASP.Net...
3
by: djozy | last post by:
I want to make asp.net application in C# that is connected with SQL Server database. When I put this connection string: SqlConnection conn = new SqlConnection( "user id=;" +...
0
by: Wee Bubba | last post by:
i have completed a Compare() function to help me sort the contents of a ListBox. I wanted to give the user of the class the ability to sort by EITHER ListItem.Text OR ListItem.Value. ALSO sometimes...
2
by: Min-su KIM | last post by:
HI~ I need to access the pointer array via DLL. Original C code is char * buf; for (int i = 0; i < 63; i++) { buf = new char ; } API_CALL(buf);
2
by: RC | last post by:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_sort2 You can see above link or read below i copy/paste from above link <script type="text/javascript"> function sortNumber(a, b)...
5
by: kazijaveed | last post by:
Hi My question is i have declared two arrays,when i enter values it shuld be store in first array after that the values of first array comes to second array with sorting iknow sorted function but...
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
0
by: JDDeviL | last post by:
Good Evening ALL, i need a help, this is my first time in using V C++. I do have a knowledge of C++. Well am trying to create a 2D array of images, i did use Array from type Bitmap and i did...
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
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...
1
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.