Click to See Complete Forum and Search --> : C++ Pointers


nikolas22t
03-28-2005, 08:03 PM
i Have this
#include <iostream.h>
#include <string.h>

int main ()
{

char in[10];
char * p;
int i,k;
float search;
cout<<"enter array"<<endl;
cin>>in;
cout<<endl<<"Enter search"<<endl;
cin>>search;
k=strlen(in);
p=in;
// method 1: index through array
for (i=0; i<10; i++)
{ if (search==in[i])

*p=i;

cout << *p << "\n";
break;


}
}

and what i want to do is
Write a C program to read through an array of any type using pointers. Write a C program to scan through this array to find a particular value.

Can anybody help me?

Exuro
03-28-2005, 10:49 PM
Have you ever heard of pointer arithmetic? That's the only thing I can think of when I look at your problem...

The problem itself seems very vague. When it says "read through an array of any type", does that mean it can read in any data-type, or that you can do it using whichever data-type you so choose? I think the latter makes more sense... If that's the case, then I would say again that pointer arithmetic is probably the answer.