Syntax error near unexpected token '('

I tried to execute the code but I got this error
./Array.c: line 9: syntax error near unexpected token '('
./Array.c: line 9: ' nvals = get_data(a,MAXARRAY);'

and

#include<stdio.h>
#define MAXARRAY 1000
main()
{
        int a[MAXARRAY],
        nvals;
        nvals = get_data(a,MAXARRAY);
        printf("Values in reverse order:\n\n");
        reverse_print(a,nvals);
}
int get_data(int vals[],int max)
{
        int n = 0;
        while (n < max && scanf("%d", &vals[n]) == 1)
        n++;
        return n;
}
int reverse_print (vals, n)
int vals[], n;
{
        int i;
        for (i =n -1; i>= 0; i--)
                printf("%d\n", vals);
}

I hope you are aware that this is a C source code file which should first be compiled for you to be able to run it...?

I did compile this file and it didn't show any error but when I execute it then it gave me error. I'm running this code in Unix. This is my first time by the way.

Please compile your code in linux like that. I compile your code, it is taking input and printing reverse order of number in return.


gcc yourcode.c -o yourcode

Regarding error, please copy "stdio.h" in your current directory where c program is there and then modify your code as per local path.


#include "stdio.h"

After you compile the code, new file is being generated (by default "a.out"). Look for it in the directory containing your source file.

1 Like

ok I did compile the code and I do see "a.out" in the directory. couldn't get to input part

---------- Post updated at 02:31 PM ---------- Previous update was at 02:28 PM ----------

ok I execute the generated "a.out" input all the integers and gave the the reverse order thank you! but why does it generated to "a.out" I want to understand how it works?

run your program like

./a.out
enter your number and then enter your name, your program will exit and reverse print the numbers.

---------- Post updated at 01:33 PM ---------- Previous update was at 01:32 PM ----------

post your compilation method/command here.

1 Like

ok thank you that is all I need to know