| | |
need help with arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 6
Reputation:
Solved Threads: 0
Hello everyone! I sure wish I would have known about this place befroe now, it would have saved some long nights. I am having probems with arrays. The situation is this read all the lines from a file and store it into an array. Once you do this, you have a character array. All your further operations should be done on the array. create a function called "Matcher". The Matcher function should go through the entire array and find how many times the string or character pattern 'aba' occurs in the entire array.
On finding a match, the program should display the index number of the array at which the string pattern started.
Once the search is complete, the program should display how many times it found the string or character pattern 'aba' in the entire array or more appropriately, in the file.
If the number of matches is zero, the program should output "Search String NOT found".
For programming purpose use this file( "file.txt"). I tried to write it with out any help and am finding I need some. I am a little older and you know what they say about teaching an old dog new tricks.
On finding a match, the program should display the index number of the array at which the string pattern started.
Once the search is complete, the program should display how many times it found the string or character pattern 'aba' in the entire array or more appropriately, in the file.
If the number of matches is zero, the program should output "Search String NOT found".
For programming purpose use this file( "file.txt"). I tried to write it with out any help and am finding I need some. I am a little older and you know what they say about teaching an old dog new tricks.
•
•
Join Date: Dec 2004
Posts: 6
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<string> #include<fstream> using namespace std; void main() { int i; int a; int b; string until; int arrayj[50]; cout<<"Jay Pilrose"<<endl; cout<<"00519995"<<endl; ifstream file1; file1.open("db.txt", ios::in); for (int k=0; k<50; k++) { file1 >> arrayj[k]; } int count=0; int arrayi[50]; for (i=0; i<50; i++) { while (i<50) { if(i=a) { i++; if(i=b) { i++; if(i=a) { cout<<"The sequence starts at "<<endl; } } else i++; until; i=a; } } } }
Another try looked much the same but used && operators and compared them on the same line. I have a hard time knowing how and what to pass in a function. I would use a void function for the matcher part but I am not sure that is the best way to go about it.
No. Debugging with cout would be like this: They are extraneous lines that during development will at least tell you what is going on in a program at a certain point. And lines that are generally removed after you've debugged and gotten portions working.
In the above example, these two lines produce this output. This can be helpful information while you're getting things working. For example, you might find that a buffer size of 50 is not big enough.
#include <iostream>
#include <fstream>
#include <cstdio>
using namespace std;
char array [ 1000 ];
int main()
{
ifstream file(__FILE__);
const char seq[] = "123";
file.getline(array, sizeof array, '\0');
const size_t len = strlen(array);
cout << "len = " << len << endl; // DEBUG
const size_t size = strlen(seq);
cout << "size = " << size << endl; // DEBUG
for ( size_t i = 0; i < len - 2; ++i )
{
if ( strncmp(&array[i], seq, size) == 0 )
{
cout << "The seq starts at " << i << endl;
cout << &array[i] << endl;
break;
}
}
return 0;
}In the above example, these two lines produce this output.
C++ Syntax (Toggle Plain Text)
len = 616 size = 3
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: please help me out with my c++ assignment!
- Next Thread: Need help With this C++ Program..Confused..
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






