Pointer problem

Joined
Oct 17, 2009
Messages
3
Reaction score
0
This is my first program I've ever written. i got most of it working but the linear seach i put in.. when i try to compile it says the second parameter does not aggree. i try to use a pointer but i must not be using it right..
anyone have a clue?

#include <stdio.h>
#include <string.h>

#define k 3
#define u 3


int lin_search( int target, int array[], int n );
int bal = 0;
int accN = 0;
int intvar = 0;
int index = 0;

struct account
{
int accountNum;
int balance;
};


int main( void )
{


struct account accInfo[4];
int aCount = 0;
int W = 0;
int f = 0;
int e = 0;
struct accInfo (*mypointer)[4];


for(aCount = 0; aCount < 4 ; aCount++ )
{

printf("Enter account number\n" );
scanf("%d", &accInfo[aCount].accountNum );

accInfo[aCount].balance = 0;
}

for (W = 0 ; W < aCount ; W++ )

{
printf("\n\nAccount number %d has a balance of %d,",accInfo[W].accountNum, accInfo[W].balance);
}


for (f = 0; f<4; f++) /*while (1)*/
{

char trans[3];
int amnt = 0;
int b = 0;



printf("\n\nEnter transaction type. \n");
scanf("%s", trans);

printf("\nEnter amount. \n");
scanf("%d",&amnt);

printf("\n\nEnter account number.\n");
scanf("%d", &accN);

index = lin_search( accN, mypointer->balance, 4); /*<------the pointer here*/


if ( index == -1 )
{
printf( "Account number not found\n\n");
}
else

{
b= accN-1;

if ( strcmp(trans,"CR")== 0)
{

accInfo.balance = accInfo.balance +amnt;

}

if ( strcmp(trans,"DB")== 0)
{

accInfo.balance = accInfo.balance - amnt;

}
}

}


for (e = 0; e< aCount; e++)
{
printf("Bank Account %d has a balance of %d\n", accInfo[e].accountNum, accInfo[e].balance);
}
return 0;
}


int lin_search( int target, int array[], int n )
{
int i;

for ( i = 0; i < n; i++)
{
if ( array[ i ] == target )

return i;

}
return -1;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top