473,480 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Incompatible type errors for the 2 arguments I'm inputting in main

1 New Member
I can't seem to fix this. I'm really new at this, and this is driving me f**king crazy. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. double calculusx[1000];
  5. double calculusy[1000];
  6. double integral0i[1000];
  7. double integrali999[1000];
  8. double derivative[1000];
  9. int i=0;
  10.  
  11.  
  12.  
  13. double Area0i(double[], double[]);
  14. double Areai999(double[], double[]); 
  15. double Slope(double[],double[]);
  16.  
  17. double Slope(double x[], double y[])
  18. {
  19. double result;
  20. result = (((x[i] - x[i-1])/(x[i+1] - x[i-1]))*((y[i] - y[i-1])/(x[i] - x[i-1]))) + (((x[i+1] - x[i])/(x[i+1] - x[i-1]))*((y[i+1] - y[i-1])/(x[i] - x[i-1])));
  21. return result;
  22. }
  23.  
  24. double Area0i(double x[], double y[])
  25. {
  26. double result;
  27. int j;
  28.     for (j=0; j<=i; j++)
  29.         {
  30.         result += ((x[i]-x[i-1])*((y[i]+y[i+1])/2));
  31.         }
  32. return result;
  33. }
  34.  
  35. double Areai999(double x[], double y[])
  36. {
  37. double result;
  38. int j;
  39.     for (j=i; j<1000; j++)
  40.         {
  41.         result += ((x[i]-x[i-1])*((y[i]+y[i+1])/2));
  42.         }
  43. return result;
  44. }
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48. int z;
  49. FILE* fp;
  50. FILE* fp2;
  51.  
  52.     if (argc<2)
  53.         {
  54.         return EXIT_FAILURE;
  55.         }
  56.  
  57.     fp = fopen(argv[1],"r");
  58.  
  59.     if (argv[i] == NULL || fp == NULL)
  60.         {
  61.         printf("Incorrect filename.\n");
  62.         return EXIT_FAILURE;
  63.         }
  64.  
  65.     fp2 = fopen("program2output.txt", "w");
  66.  
  67.     for (z=0; z<1000; z++)
  68.         {
  69.         fscanf(fp, "%lf %lf", &calculusx[z], &calculusy[z]);
  70.         }
  71.  
  72.     for (i=0; i<1000; i++)
  73.         {
  74.         integral0i[i] = Area0i(calculusx[i], calculusy[i]);
  75.         integrali999[i] = Areai999(calculusx[i], calculusy[i]);
  76.         derivative[i] = Slope(calculusx[i], calculusy[i]);
  77.  
  78.         fprintf(fp2, "%5.3lf\t%5.3lf\t%5.3lf\t%5.3lf\t%5.3lf\n", calculusx[i],calculusy[i], integral0i[i], integrali999[i], derivative[i]);
  79.         }
  80.  
  81.     fclose(fp);
  82.     fclose(fp2);
  83.  
  84. return EXIT_SUCCESS;
  85.  
  86. }

The program is meant to read a list of inputs from a file, store then in two arrays I have named calculusx and calculusy, perform some math on them, and then spit the outputs into another file.

The problem is, whenever I try to compile, the three functions I call in main (integral0i, integrali999, and derivative) give me errors that the arguments in the functions are of an incompatible type. I swear that I've defined the arrays as doubles, the functions return a double, and that I am putting in doubles as my argument. Can somebody please help me with this, it is driving me insane.
Mar 11 '10 #1
1 2588
Banfa
9,065 Recognized Expert Moderator Expert
Vut you define the parameters of your functions as pointers to doubles not doubles but you are passing them doubles.

Also all you data is global and that is really bad practise.

Look at you function Slope, defined like this

Expand|Select|Wrap|Line Numbers
  1. double Slope(double x[], double y[])
  2. {
  3.     double result;
  4.     result = (((x[i] - x[i-1])/(x[i+1] - x[i-1]))*((y[i] - y[i-1])/(x[i] - x[i-1]))) + (((x[i+1] - x[i])/(x[i+1] - x[i-1]))*((y[i+1] - y[i-1])/(x[i] - x[i-1])));
  5.     return result;
  6. }
  7.  
Called like this
Expand|Select|Wrap|Line Numbers
  1. derivative[i] = Slope(calculusx[i], calculusy[i]);
The parameters passed to the function do not match the parameters it is expecting. Additionally the function uses i with is declared globally and uses the expression x[i-1] even though i might be 0.

i should be passed to all your functions the functions should not use the global variable. This is encapsulation, by encapsulating the data the function uses within the function itself you protect it from outside interference and make it more robust and easier to maintain. The function should check the value of i passed to it and make sure that its valid.

These declarations
Expand|Select|Wrap|Line Numbers
  1. double calculusx[1000];
  2. double calculusy[1000];
  3. double integral0i[1000];
  4. double integrali999[1000];
  5. double derivative[1000];
  6. int i=0;
  7.  
Should be inside main. However you should not put large arrays on the stack so calculusx and calculusy should either be declared static or be allocated from the heap. integral0i, integrali999 and derivative do not need to be arrays since they are only used locally to the loop in the main function.
Mar 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
2303
by: Terje Slettebø | last post by:
Hi. I'm new here, and sorry if this has been discussed before; I didn't find it searching the PHP groups. (I've also read recommendations to cross-post to the other PHP groups, but if that is...
15
9318
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
2
4162
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
6
5242
by: PraZ | last post by:
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it...
4
4928
by: Harold Howe | last post by:
I am running into a situation where the compiler complains that it cannot infer the type parameters of a generic method when one of the function arguments is an anonymous method. Here is a...
8
3249
by: Michael | last post by:
Hi all, why do I get a message: warning: passing arg 1 of `collectInput' from incompatible pointer type In 'main' have: char inputString; collectInput(&inputString);
8
24205
by: fei.liu | last post by:
I have the following source code. It seems wierd to me why gca's value cannot be reassigned. It's afterall a pointer and has a pointer value. I am aware that the standard says it's not allowed. But...
1
2847
by: pyo2004 | last post by:
Here's the definition of work_struct struct work_struct { unsigned long pending; struct list_head entry; void (*func)(void *); void *data; void *wq_data; struct timer_list timer; };
5
1558
by: subramanian100in | last post by:
I am copying the following text as it is from Stroustrup's TC++PL 3rd edition, page 450. It says: "Note that a constructor given two arguments of the same type can be a match for more than...
7
1421
by: sumsin | last post by:
Why the below two code snippet behave differently Case 1: #include <iostream> void foo(const int *i) { int *local = i; }
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.