# Thread: Loop Help with Pointers.

1. ## Homework Help Pointers/Manipulation of array.

I am not sure where my problem is but here is the question asked of me and what I have so far.

I can get 2 to display however the rest seem to be non existant.

# Write a C program that has a declaration in main() to store the following numbers into an array named channels: 2, 4, 5, 7, 9, 11, 13. There should be a function call to display() that accepts the channels as an argument named channels and then displays the numbers using the pointer notation *(channels + i).

# Modify this
display() function to alter the address in channels. Always use the expression *channels rather than *(channels + i) to retrieve the correct elements

Code:
```#include <stdio.h>

#define nums 7
void display(int*,int);

int main()
{
int x;
int channels[nums]={2,4,5,7,9,11,13};
printf("Channels: ");

void display(int *channels, int x);

printf("%4d", *channels);

return 0;
}
void display(int *channels,int x)
{
for(x=0; x<nums; x++)
{
*channels++;
}
}```

2. void display(int *channels, int x);
should be
Code:
`display(channels,nums);`
for(x=0; x<nums; x++)
should be
Code:
`for(i=0;i<x;i++)`
*channels++;
should be...
read once more the assignement, it should include 2 things
output function, for example printf and *(channels + i)

3. now i did part a of the assignment and unsure on part b.

i rewrote code after watching a few videos

here is the improved code.

Code:
```#include <stdio.h>
#define nums 7

void display(int *);

int main()
{

int channels[nums]={2,4,5,7,9,11,13};
display(channels);
}
void display(int *channels)
{
int i;
for(i=0;i<nums;i++)
{
printf("%5d",*(channels+i));
}
}```
Now I am stuck on manipulation of the display() to use *channels rather than *(channels+i) to retrieve the correct elements.

4. Nevermind here is the solution for all glad I helped myself, with some help from someone.

Part A
Code:
```#include <stdio.h>
#define nums 7

void display(int *);

int main()
{

int channels[nums]={2,4,5,7,9,11,13};
printf("Channels:");
display(channels);
}
void display(int *channels)
{
int i;
for(i=0;i<nums;i++)
{
printf("%5d",*(channels+i));
}
}```
Part B

Code:
```#include <stdio.h>
#define nums 7

void display(int *);

int main()
{

int channels[nums]={2,4,5,7,9,11,13};
printf("Channels:");
display(channels);
}
void display(int *channels)
{
int i;
for(i=0;i<nums;i++)
{
printf("%5d",*channels);
*channels++;
}
}```