0

having an issue while running my code on cygwin only getting one error which is at line 11. please spare me as i am a beginner. Trying to solve it from 8 hours straight but no luck edited the error to match the source code tried add an int between typedef int (*fun_ptr)... still same erroe

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define RED "\033[0;31m"
#define GREEN "\033[0;32m"
#define BLUE "\033[1;34m"
#define RESET "\033[0m"

typedef (*fun_ptr)(int**, int, int, char**, int, int);

void printBoard(int **board, int b_height, int b_width)
{
    int i, j;
    char ch;
    printf(":) ||");
    for (j = 0; j < b_width; j++)
    {
        printf(" %c |", 'A' + j);
    }
    printf("\n---++");
    for (j = 0; j < b_width; j++)
    {
        printf("===+");
    }
    for (i = 0; i < b_height; i++)
    {
        printf("\n %d ||", i + 1);
        for (j = 0; j < b_width; j++)
        {
            if (board[i][j] == -1)
            {
                ch = 'X';
                printf(" %s%c%s |", RED, ch, RESET);
                //printf(" X |");
            }
            else if (board[i][j] == -2) {
                ch = '0';
                printf(" %s%c%s |", GREEN, ch, RESET);
                //printf(" 0 |");
            }
            else {
                ch = '#';
                printf(" %s%c%s |", BLUE, ch, RESET);
                //printf(" # |");
            }
        }
        printf("\n---++");
        for (j = 0; j < b_width; j++)
        {
            printf("---+");
        }
    }
    printf("\n");
}




error that i am getting

./source.c: line 11: syntax error near unexpected token `('
./source.c: line 11: `typedef (*fun_ptr) (int**, int, int, char**, int, int);'
9
  • are you using gcc - how are you compiling it? Commented Jul 18, 2020 at 0:16
  • The line in the code doesn't look like the line in the error message. Commented Jul 18, 2020 at 0:17
  • 1
    So I don't think you posted the same source file that got the error. Commented Jul 18, 2020 at 0:18
  • 1
    Please edit the question, make the title, code, and error message match. Commented Jul 18, 2020 at 0:23
  • 1
    When I compile the code in your question with gcc on Cygwin, I get warning: type defaults to ‘int’ in declaration of ‘fun_ptr’ [-Wimplicit-int], not a syntax error. When I add int after typedef, it compiles without error. If you're getting a syntax error after adding int, the problem is in code you haven't shown us. This is why we need a minimal reproducible example (read that link). Commented Jul 18, 2020 at 1:27

1 Answer 1

1
typedef (*fun_ptr)(int**, int, int, char**, int, int);

That's almost how you'd define a name fun_ptr for a pointer-to-function type. The only thing missing is the return type of the function. For example, if it returns int:

typedef int (*fun_ptr)(int**, int, int, char**, int, int);

(It looks like your code is incomplete, since you don't have any functions of that type, nor do you use fun_ptr. I presume you're just not finished.)

Sign up to request clarification or add additional context in comments.

5 Comments

not really now it gives is this error ./source.c: line 11: syntax error near unexpected token (' ./source.c: line 11: typedef int (fun_ptr) (int*, int, int, char**, int, int);'
That I cannot reproduce. The only error I get when compiling your code and adding the missing return type is a linker error because there is no main. If you did not type this in yourself, make sure you didn't copy an invisible character or unicode character that looks like a ( but isn't.
@AwaisAkbar typedef int (fun_ptr) (int*, int, int, char**, int, int); is a syntactically valid declaration. If you're getting a syntax error, it's because of a problem on a previous line -- code that you didn't show us. This kind of thing is why we need a minimal reproducible example.
@awaisakbar you are missing a * before fun_ptr: try with (*fun_ptr).
@RobertoCaboni note how the text suddenly turns italics. That's the missing *.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.