# Thread: Pointers and Function calls

1. ## Pointers and Function calls

Hi,

I'm learning about pointers from a c programming book, and I tried to do some of the exercise problems.

In the book, every 'program' is written as one function with a main. But I'm trying to combine multiple 'programs' as functions, then call them in main. Trouble is, a lot of these functions take pointers as args, so I'm not sure how to call them in main with actual values.

I put these functions inside of main [to try to get around the problem] but it cannot compile. I'm getting 'need ; before {' errors in main, but ofc I checked and don't need any ;'s before {'s.

My code:
Code:
```int division(int numerator, int denominator, int *dividend, int *remainder) {

if (denominator == 0)
return(0);
*dividend=numerator/denominator;
*remainder=numerator%denominator;
return(1);

}

main() {

functioncall1();

functioncall2();

functioncall3();

functioncall4() {
int x, y, d, r;
x=9;
y=2;
division(x, y, &d, &r);
printf("%d/%d = %d with %d remainder\n",x,y,d,r);
printf("x=%d\n",x);
}

functioncall5() {

double array[10];
double *d_ptr;
double value;
int i,offset;
for (i=0; i<10; i++)
array[i]=(double)i+10.0; /* access memory using array index and fill cells with #s*/
d_ptr=&(array[0]); /* access memory location of first array cell using pointer*/
while (1) {
for (i=0; i<10; i++)
printf("%p\t%u\t%lf\n",&(array[i]),&(array[i]),array[i]);
printf("Enter offset value (0 0 to quit): ");
scanf("%d %lf",&offset,&value);
if (offset == 0 && value == 0.0)
break; /* break out of loop */
if (offset < 0 || offset > 9) {
printf("Offset out of bounds\n");
continue; /* go back to start of loop */
}
array[offset]=value; /* using array syntax */
}
return (0);
}
}```

2. Please don't be offended... but if you can't figure this out... you need to do some serious reviewing, cause it clearly didn't sink in the first time!

Some of the problems... you cannot nest functions inside main in C... it will hate you forever. You really need to give your functions descriptive names "GetName" or "ReadDiskFile".... and there's more.

Also as a little hint... No, you don't always get to just pile stuff in together... code in C is not always "interchangeable" and often you cause more problems than you solve. Best bet, if you want to combine some aspects of one exercise with those of another... here's a project for you... scratch write the thing. I guarantee you'll learn a lot more than you will by copying blocks of code from here to there... (We call that "scoop and poop" coding, btw)