# Web Development

## General discussion

Locked

### Programming C

By ·
Can someone help me to get the c program below to run?
Thanks

//
// array2.c -- Read/writing/reversing integer arrays
//

#include <stdio.h>

#define NMAX 10

void intSwap(int *x, int *y);
int getIntArray(int a[], int nmax, int sentenel);
void printIntArray(int a[], int n);
void reverseIntArray(int a[], int n);

int main(void)
int x[NMAX];
int hmny;

hmny = getIntArray(x, NMAX, 0);
printf("The array was: \n");
printIntArray(x,hmny);
reverseIntArray(x,hmny);
printf("after reverse it is:\n");
printIntArray(x,hmny);
}

void intSwap(int *x, int *y)
/* It swaps the content of x and y */
{
int temp = *x;
*x = *y;
*y = temp;
}

void printIntArray(int a[], int n)
/* n is the number of elements in the array a.
* These values are printed out, five per line. */
{
int n;

for (i=0; i<n; ){
printf("\t%d ", a);
if (i%5=0)
printf("\n");
}
printf("\n");
}

int getIntArray(int a[], int nmax, int sentinel)
/* It reads up to nmax integers and stores then in a; sentinel
* terminates input. */
{
int n = 0;
int temp;

do {
printf("Enter integer [%d to terminate] : ", sentinel);
scanf("%d", &temp);if (temp==sentinel) break
if (n==nmax)
printf("array is full\n");
else
a[n+] = temp;
}while (1);
return n;
}

void reverseIntArray(int a[], int n)
/* It reverse the order of the first n elements of a */
{
int i;

for(i=0;i<n/2;i++){
intSwap(&a,&a[n-i-2]);
}
}

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

Collapse -

### Programming C

by In reply to Programming C

Here's what I can see...

int main(void)
Missing opening brace "{" for start of function main()

if (i%5=0)
Missing opening brace "{" in function printIntArray()
Illegal comparison - possibly mean if((i%5)==0)

if (temp==sentinel) breakMissing semicolon ";"

a[n+] = temp;
Possibly mean post-increment n - a[n++] = temp;

intSwap(&a,&a[n-i-2]);
Logic error: possibly mean a[n-i-1]

}
Extra closing brace at end-of-file.

Collapse -

### Programming C

by In reply to Programming C

Thanks

Collapse -

### Programming C

by In reply to Programming C

This question was closed by the author

## Related Discussions

• 12

• 23

• 1

#### Best Framework for Web Developement?

iftikharqureshi ·

• 5

inextures ·

• 10

#### Best software to design Simple Website?

matthewjohn938 ·