New to C, a few 'invalid conversion' and 'too few arguments' errors

This is my first timne doing an actual project in c, I'm getting a lot of the same errors so I assume its just the same mistake in a few places, any help would be appreciated. Also I am, unsure as to how to print the results as a table so again any advice greatly appreciated!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include<stdlib.h>
#include<stdio.h>
#include<math.h>

int get_capacitance(int);
int get_inductance(int);
int frequency_gen(int[]);
int capacitive_reactance(int,int[],int[]);
int inductive_reactance(int,int[],int[]);
int attenuation_ratio(int,int,int[]);
int attenuation_db(int[]);


int main(int argc, char*argv[])
{
    int cap,ind;
    int frequencies[18];
    int cap_reactance[18];
    int ind_reactance[18];
    int att_ratio[18];
    int att_db[18];
    
    get_capacitance(cap);
    get_inductance(ind);
    frequency_gen(frequencies);
    capacitive_reactance(cap_reactance);
    inductive_reactance(ind_reactance);
    attenuation_ratio(att_ratio);
    attenuation_db(att_db);
  
    
    
    
    getchar();
    return 0;
}

int get_capacitance(int cap);
{
    printf("Enter Capacitor value in uF\n");
    scanf("%i",cap);
    return cap;
}

int get_inductance(int ind);
{
    printf("Enter Inductor value in mH\n";
    scanf("%i",ind);
    return ind;
}

int frequency_gen(int frequencies[18]);
{
  int inc[2] = { 100, 1000 };                                                          //Generates array of two increments//
  int freq = 100;
  int n;

  for( n = 0; n < 18; n++ )
  {
    frequencies[n] = freq;                                                            //Assigns value of freq to start of array//

    freq += (n < 9) ? inc[0] : inc[1];                                                  //If n<9 the first value of array inc is used(100), n>9 second value is used//
   }     
   return frequencies;
}


int capacitive_reactance(int cap,int frequencies[18],int cap_reactance[18]);
{
    int n;
    for (n=0; n<18; n++)
    {
        cap_reactance[n]=1/(2*3.14*frequencies[18]*(cap*pow(10,-6)));
        return cap_reactance;
    }
}

int inductive_reactance (int ind, int frequencies[18], int ind_reactance);
{
	int n;
	for (n=0; n<18; n++)
	{
		ind_reactance[n] = 2*3.14*frequencies[18]*(ind*pow(10,-3));
		return ind_reactance;
		
	}
}

int attenuation_ratio (int cap,int ind, int frequencies[18]);
{
	int n;
	for (n=0; n<18; n++)
	{
	
	int omega;
	omega = 2*3.14*frequencies[18];
	att_ratio[n] = (pow(omega,2)*cap*ind)/((pow(omega,2)*cap*ind)-1);
	return att_ratio;
    }
}

int attenuation_db(int att_ratio[18]);
{
	int n;
	for (n=0; n<18; n++)
	{
		att_db[n] = 20*log10(att_ratio[18]);
		return att_db;
    }
}
Last edited on
Notice how you do not pass as many arguments as the functions need.
For instance, capacitive_reactance() expects one int and two int arrays int[], that is three parameters -- and you only feed it one argument when you call it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int get_capacitance(int);
int get_inductance(int);
int frequency_gen(int[]);
int capacitive_reactance(int,int[],int[]);
int inductive_reactance(int,int[],int[]);
int attenuation_ratio(int,int,int[]);
int attenuation_db(int[]);

// later on...

    get_capacitance(cap);
    get_inductance(ind);
    frequency_gen(frequencies);
    capacitive_reactance(cap_reactance);
    inductive_reactance(ind_reactance);
    attenuation_ratio(att_ratio);
    attenuation_db(att_db);
Okay so if I were to say capacitive_reactance(cap,frequencies,cap_reactance) then it should work?
Cheers that solved one problem but the one that I and someone else I've shown can't work out is
' expected unqualified-id before '{' token '
' expected `,' or `;' before '{' token '
This comes up for every function but unless I'm being impressively blind I can't see that there is anything missing
An immediate problem I see is that in your functions you try to access variables defined in main(), such as att_ratio[18] and att_db[18].

Variables defined inside a function are called "local" variables and cannot be seen in other functions. This applies to the main() function as well.

So a quick solution is to move some of the variables out of main() and make them "global". Global variables are defined outside any function -- and can be seen by any function in the erm... translation unit... a good enough approximation of which being "the current file".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

int global = 55;

void func()
{
    int local = 1;

    printf("func: global: %d\n", global); // can see global
    printf("func: local: %d\n", local);
}

int main()
{
    int local = 2;

    printf("main: global: %d\n", global); // can see global
    printf("main: local: %d\n", local);

    func();
}

Topic archived. No new replies allowed.