'Expected Primary expression before int inside a function [closed]
I am very aware that a lot of the formatting of this code is likely to be completely wrong. I am attempting to create a function GenPathByNumber which itself calls a function Binary. The GenPathBynumber attempts to (for integer x values from 0 through to 2^N - 1) create an array Path for each x value, with entries corresponding to each digit of x's binary representation. Binary converts each x to its binary reresentation, and GenPathByNumber puts binary through a loop. When trying to build this, the logs keep saying "Expected Primary expression before int" for the Binary function (line 10 in the code below). Please can someone tell me what the problem(s) are?
void GenPathByNumber(int x,int N,int *Path)
{
//Create the array Path of length N, with all entries set to 0
Path[N] = {0};
//runs a for loop of all x values up to 2^N - 1
//and generates a binary path corresponding to each number
// of length N, then stores each digit of this in array Path.
for (int x = 0; x < pow(2,N)-1; x++)
{
binary(int x, int* Path);
}
}
void binary(int x, int* Path) {
if (x == 0) {
printf("%s\n", Path);
} else {
Path[x-1]='0';
binary(x-1);
Path[x-1] = '1';
binary(x-1);
}
}
Solution 1:[1]
Inside the for loop in GenPathByNumber you have:
for (int x = 0; x < pow(2,N)-1; x++)
{
binary(int x, int* Path);
}
You don't need the argument type specifiers when you call a function, only when you define it. Remove those and the error goes away.
binary(x, Path);
You have other errors inside the binary function where you're calling it with only one argument, like binary(x - 1);. You probably mean to provide Path in those calls as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bill the Lizard |
