473,624 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

want to search in a text file if it contains the words present i a 2d array..

4 New Member
i hav a text file anagrams.text.. .....and i hav a 2d array r[6][4]....i want to search in the text file anagrams.txt the words present in the 2d array and if present print them....thanx.. ..(im trying to implement genetic algorithm on anagrams)..
............... ............... ............... ............... ............... ............... ............... ..............
Expand|Select|Wrap|Line Numbers
  1. #include <time.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <iostream>
  6. #include <string.h>
  7. using namespace std;
  8.  
  9. char reply='y';
  10. int j=0;
  11. main()
  12. {
  13.   while(reply=='y')
  14.   {
  15.   char s[3];
  16.  
  17.   char r[6][4];
  18.   char arr[6][4];
  19.  
  20.   cout<<"\nenter the 4 letter word";
  21.   cin>>s;
  22.   cout<<"\nthe 1st letter  is\t"<<s[0]<<"\n";
  23.   cout<<"\nthe 2nd letter  is\t"<<s[1]<<"\n";
  24.   cout<<"\nthe 3rd letter  is\t"<<s[2]<<"\n";
  25.   cout<<"\nthe 4th letter  is\t"<<s[3]<<"\n";
  26.  
  27.     cout<<"\n\n";
  28.  
  29.  
  30.   int rolls=24;
  31.  
  32.   srand((unsigned int)time((time_t *)NULL));
  33.   cout<<"\nthe possible allel combinations are \n\n"<<"\n";
  34.  int a=1;
  35.  int b=1;
  36.  
  37.   while(rolls--)
  38.   {
  39.      int i=((rand()%4)+0);
  40.  
  41.     if(i==0)
  42.     {
  43.        r[b][a]=s[0];
  44.        arr[b][a]=s[0];
  45.  
  46.        cout<<r[b][a];
  47.      }
  48.  
  49.     else
  50.     if(i==1)
  51.     {
  52.  
  53.        r[b][a]=s[1];
  54.        arr[b][a]=s[1];
  55.        cout<<r[b][a];
  56.        }
  57.     else
  58.     if(i==2)
  59.     {
  60.        r[b][a]=s[2];     
  61.        arr[b][a]=s[2];
  62.       cout<<r[b][a];
  63.  
  64.     }
  65.  
  66.     else
  67.     if(i==3)
  68.     {
  69.     r[b][a]=s[3];
  70.     arr[b][a]=s[3];
  71.     cout<<r[b][a];
  72.  
  73.     }
  74.  
  75.     a++;
  76.  
  77.  
  78.     if(a>4)
  79.     {
  80.  
  81.       a=1;
  82.       b++;
  83.     }
  84.  
  85.  
  86.  
  87.     j++;
  88.     if(j==4)
  89.     {
  90.       printf(" \n\n");
  91.       j=0;
  92.     }
  93.  
  94.  
  95.  
  96.   }
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. // crossover
  104.  
  105. cout<<"\n\n after cross over\n\n";
  106.  
  107. arr[1][3]=r[2][3];
  108. arr[1][4]=r[2][4];
  109. arr[2][3]=r[1][3];
  110. arr[2][4]=r[1][4];
  111. arr[3][3]=r[4][3];
  112. arr[3][4]=r[4][4];
  113. arr[4][3]=r[3][3];
  114. arr[4][4]=r[3][4];
  115. arr[5][3]=r[6][3];
  116. arr[5][4]=r[6][4];
  117. arr[6][3]=r[5][3];
  118. arr[6][4]=r[5][4];
  119. int h=0;
  120. int m=1;
  121. int n=1;
  122. int roll=24;
  123. while(roll--)
  124. {
  125.  
  126.  
  127.  
  128. cout<<arr[m][n];
  129.  
  130. n++;
  131.  
  132.  
  133.     if(n>4)
  134.     {
  135.  
  136.       n=1;
  137.       m++;
  138.     }
  139.  
  140.  
  141.  
  142.     h++;
  143.     if(h==4)
  144.     {
  145.       printf(" \n\n");
  146.       h=0;
  147.     }
  148.  
  149.  
  150. }


cout<<"want to try again ? (y/n)";
cin>>reply;
}
getch();
}


------------------------------------------------------------------------------------------------------------------

anagrams.txt
---------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. abed
  2. bade
  3. bead
  4. abet
  5. beat
  6. beta
  7. abut
  8. tabu
  9. tuba
  10. acme
  11. came
  12. mace
  13. acre
  14. care
  15. race
  16. ales
  17. leas
  18. sale
  19. seal
  20. amen
  21. mane
  22. mean
  23. name
  24. anew
  25. wane
  26. wean
  27. arcs
  28. cars
  29. scar
  30. asps
  31. pass
  32. saps
  33. spas
  34. awls
  35. laws
  36. slaw
  37. bard
  38. brad
  39. drab
  40. bats
  41. stab
  42. tabs
  43. brag
  44. garb
  45. grab
  46. code
  47. coed
  48. deco
  49. dale
  50. deal
  51. lade
  52. lead
  53. dare
  54. dear
  55. read
  56. diet
  57. edit
  58. tide
  59. tied
  60. demo
  61. dome
  62. mode
  63. diet
  64. edit
  65. tide
  66. tied
  67. does
  68. dose
  69. odes
  70. dues
  71. sued
  72. used
  73. ears
  74. eras
  75. sear
  76. rose
  77. sore
  78. ores
Apr 16 '10 #1
2 1717
Banfa
9,065 Recognized Expert Moderator Expert
You need to revisit your text book/reference material and read about how arrays work. An array

int array[4];

Has the number of entries given in the definition, 4 in this case, and they are numbered from 0 so valid indexes for this case are 0, 1, 2, 3

A string is and array of characters with a terminating 0, that is the nul character or '\0' at the end of the array. To hold a string of 4 characters say "made" you need an array of 5 characters

char word[5];

4 to hold the printable characters and a final one for the terminator.

You code is full of instances of writing outside the array boundaries because the index is too high. This results in undefined behaviour which is bad because anything can happen.
Apr 16 '10 #2
shane12345
4 New Member
@Banfa
ya it works now...my array indexes were not proper....thanx .
Apr 17 '10 #3

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

Similar topics

0
5764
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default setting whereby the minimum amount of characters is 4 for a search. Being that we're government and full of TLA (three-letter acronyms), that is not practical, and furthermore, the app I'm building must be fully portable, so having MySQL tweaked...
3
1633
by: Fred Yarbrough | last post by:
We have a simple html page that contains a long list of documents that users can hyperlink to. The entries are currently in alphabetical order and we would like to implement some type of page search instead of requiring users to go to Edit, Find, and type in the search. I am very new to ASP but suspect that this is possible. We would simply like to have a SEARCH box at the top of the page and it allows users to search only the current...
8
2401
by: Rob Meade | last post by:
Lo all, Ok - I'm adding site search functionality to a database driven website. I have a list of 390 stop/ignore words, having looked at ASPFAQ already I see that the example uses an array, what I was wondering was whether this would still be the best practice for this quantity of stop words? There is a larger over head in me defining the array initially as I will have to hard code them all in, alternatively I thought I could import...
3
15324
by: Trevor Fairchild | last post by:
I'm trying to execute a full-text query from a vb.net web application. The problem I have is that in SQL Server, the syntax for a full-text search is SELECT * FROM table WHERE CONTAINS( *, ' "searchstring" ') For whatever reason, VB won't run that search string unless I eliminate
4
10190
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function filter() { var items = new Array("John", "Jane");
7
728
by: Arnold | last post by:
I need to read a binary file and store it into a buffer in memory (system has large amount of RAM, 2GB+) then pass it to a function. The function accepts input as 32 bit unsigned longs (DWORD). I can pass a max of 512 words to it at a time. So I would pass them in chunks of 512 words until the whole file has been processed. I haven't worked with binary files before so I'm confused with how to store the binary file into memory. What sort of...
5
4174
by: JP SIngh | last post by:
Hi All This is a complicated one, not for the faint hearted :) :) :) Please help if you can how to achieve this search. We have a freetext search entry box to allow users to search the database. I am searching two tables. SELECT TapeRecords.Id, TapeRecords.ItemTitle, TapeRecords.SourceRef,
91
7752
by: jerger | last post by:
I want to help teach to a minority group in Milwaukee, so I want to create a dictionary program that translates a sentence (like a homework problem or teacher instructions), from English into Hmong. I have one Idea, and that is to have an English text file of all the A-words, then a Hmong text file of the proper translations. Each text file would have the same amount of lines, with one english word per line, then translated to hmong. Would it...
0
1757
by: Skywick | last post by:
Hi I am trying to do a full text search with a column name for the search term. I can do this using LIKE with: SELECT tblContent.ID FROM tblContent INNER JOIN #keywords ON tblContent.words LIKE '%' + #keywords.keyword + '%' But I can not seem to do this using the CONTAINS syntax. eg.
0
6972
by: Atos | last post by:
Binary search is used to locate a value in a sorted list of values. It selects the middle element in the array of sorted values, and compares it with the target value; that is the key we are searhing for in the array. If it islower than the target value then the search is made after that middle element and till the end of the array. If it is equal then the target value is found and the middle is returned. Otherwise, search is made from the...
0
8174
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
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...
1
8336
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7164
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
6111
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...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
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
1485
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.