Post the code you've got between [CODE][/CODE] tags. Quid pro quo .
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
>if(i=a)
This is assigning the value of a to i and then evaluating whether i is nonzero. Use if(i==a).
Why do you take input into an array of int if it is supposed to be an array of char?
>void main()
Use int main().
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Try adding some debugging statments to help you as you go. Just use cout to display something you may be curious about. This will be one way to answer your own questions as you go.
Are you required to do user input char by char, or are you allowed to use other standard functions such as getline?
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
No. Debugging with cout would be like this:
#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;
}
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.
len = 616
size = 3
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.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314