Jump to content

C Programming error

Cruiseshipfan
Go to solution Solved by MikeD,

You should provide more details about your problem. Even if you do not want to share the function itself it would be best to see the actual code structure.

 

From the limited information here I would say check the function prototype if you have one. The mismatch may have occurred there.

I didn't feel like starting a new thread, for this but here is another issue. We haven't really been an explanation on how to read from a file which we need to do. Our text book just uses fopen but due to visual studios 2012, we cannot use that and we have no information on how to correctly set it up for fopen_S and fscanf_s, so I looked at some other codes and had a guess at it, but it telling me I have uninitialized variables, so either the code is wrong or it cannot find the file. Can someone check this code as this is where I am having an issue. 

 

FILE *in;

 

fopen_s(&in, "input1.dat", "r");

 

status = fscanf_s(in,"%lf,%lf,%lf,%lf,%lf,%lf", &b_input, &c_input, &d_input, &e_input, &range_l, &range_h);

 

ORIGINAL POST--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

I have a programming assignment to find the roots of a quartic. I am almost complete but I have an issue in my coding but I cannot figure out why it is doing it. I am only a beginner so I don't really know much yet, so please forgive stupidity.

 

Visual Studios gives me this error
 

 

error C2660: 'section' : function does not take 8 arguments

This is my function its is talking about. 
double section(double b_input,double c_input,double d_input,double e_input,double range_l, double range_h,double last_v, int root_num)

 

and this is the line that is saying is the issue 

root_num = section( b_input, c_input, d_input, e_input, range_l, range_h, t_root, root_num);

 

Am I miss counting as there seems to be eight to me. 

My PC:

Case: NZXT Phantom 420 | Motherboard: Gigabyte GA-Z77X-UD3H-WB WIFI | PSU: Corsair TX650M | CPU: Intel 3570k | CPU Cooler: Corsair H60 with Corsair SP120s in push pull | GPU: AMD 7970 GV-R797OC-3GD | RAM: 16GB Corsair Vengeance 4x4GB | SSD: Samsung 830 256GB | HDD: Seagate Barracuda 2TB
Link to comment
Share on other sites

Link to post
Share on other sites

You should provide more details about your problem. Even if you do not want to share the function itself it would be best to see the actual code structure.

 

From the limited information here I would say check the function prototype if you have one. The mismatch may have occurred there.

Link to comment
Share on other sites

Link to post
Share on other sites

can you do you clean-build, probably you changed the section(...) function recently and the binary is not rebuilt properly.

Link to comment
Share on other sites

Link to post
Share on other sites

You should provide more details about your problem. Even if you do not want to share the function itself it would be best to see the actual code structure.

 

From the limited information here I would say check the function prototype if you have one. The mismatch may have occurred there.

Yes it was an issue in the function prototype. I don't know how I didn't spot it when I first checked. I think it was because I did a copy and paste to make sure they were correct but then needed to change it later one. However it did seem to be hiding a bunch of other errors, which lucky for me were pretty easy to fix.  Thanks. 

My PC:

Case: NZXT Phantom 420 | Motherboard: Gigabyte GA-Z77X-UD3H-WB WIFI | PSU: Corsair TX650M | CPU: Intel 3570k | CPU Cooler: Corsair H60 with Corsair SP120s in push pull | GPU: AMD 7970 GV-R797OC-3GD | RAM: 16GB Corsair Vengeance 4x4GB | SSD: Samsung 830 256GB | HDD: Seagate Barracuda 2TB
Link to comment
Share on other sites

Link to post
Share on other sites

I didn't feel like starting a new thread, for this but here is another issue. We haven't really been an explanation on how to read from a file which we need to do. Our text book just uses fopen but due to visual studios 2012, we cannot use that and we have no information on how to correctly set it up for fopen_S and fscanf_s, so I looked at some other codes and had a guess at it, but it telling me I have uninitialized variables, so either the code is wrong or it cannot find the file. Can someone check this code as this is where I am having an issue. 

 

FILE *in;

 

fopen_s(&in, "input1.dat", "r");

 

status = fscanf_s(in,"%lf%lf%lf%lf%lf%lf", &b_input, &c_input, &d_input, &e_input, &range_l, &range_h);

My PC:

Case: NZXT Phantom 420 | Motherboard: Gigabyte GA-Z77X-UD3H-WB WIFI | PSU: Corsair TX650M | CPU: Intel 3570k | CPU Cooler: Corsair H60 with Corsair SP120s in push pull | GPU: AMD 7970 GV-R797OC-3GD | RAM: 16GB Corsair Vengeance 4x4GB | SSD: Samsung 830 256GB | HDD: Seagate Barracuda 2TB
Link to comment
Share on other sites

Link to post
Share on other sites

Again, some more information about the error, the code and the structure of the input file would be important.

 

I am testing this on Linux, meaning I am using different versions of the functions. But guessing what you are trying to do and guessing the structure of the file it works fine for me.

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm, haven't compiled c code in 2012, but in 2010 you can still use fopen...it just throws a warning given it isn't "safe" (the fopen_s is windows only...it doesn't work on other platforms).

 

Remember to #include <stdio.h>

Anyways you could probably use fopen if your don't care about the warnings VS will give

As MikeD said, you didn't give enough information to actually diagnose things....the best I could guess is that it is just a Warning and not an Error about the in variable being "used" before being initialized (two very different things in VS C++)...I don't know though, only a guess from looking at your small bit of code.

 

As a little note of what would be helpful.

Create a little program like

int main(...) {

   //Read in files here, with all relevant test variables needed.

}

and do your testing in there...if you get errors then you can just post the main function with the exact error, and thus we can see better where the errors are coming from.

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm, haven't compiled c code in 2012, but in 2010 you can still use fopen...it just throws a warning given it isn't "safe" (the fopen_s is windows only...it doesn't work on other platforms).

 

Remember to #include <stdio.h>

Anyways you could probably use fopen if your don't care about the warnings VS will give

As MikeD said, you didn't give enough information to actually diagnose things....the best I could guess is that it is just a Warning and not an Error about the in variable being "used" before being initialized (two very different things in VS C++)...I don't know though, only a guess from looking at your small bit of code.

 

As a little note of what would be helpful.

Create a little program like

int main(...) {

   //Read in files here, with all relevant test variables needed.

}

and do your testing in there...if you get errors then you can just post the main function with the exact error, and thus we can see better where the errors are coming from.

I am not sure whether 2012 needs it, but we are required to do it in the project. I managed to get it to work. Visual studios is being absolutely horrible. Sorry I cannot give much information due to it being an assignment. 

My PC:

Case: NZXT Phantom 420 | Motherboard: Gigabyte GA-Z77X-UD3H-WB WIFI | PSU: Corsair TX650M | CPU: Intel 3570k | CPU Cooler: Corsair H60 with Corsair SP120s in push pull | GPU: AMD 7970 GV-R797OC-3GD | RAM: 16GB Corsair Vengeance 4x4GB | SSD: Samsung 830 256GB | HDD: Seagate Barracuda 2TB
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×