Jump to content

Really need help with C functions. Short on time

SpaceAgentX

Okay I'll be honest here I got a project for school due soon and I need help. I have to convert an array program i made in C to use functions. The program ask the user to enter up to 20 integers and it then list the numbers entered, list them with duplicates removed and then prints the numbers with dupes removed in ascending order. I basically need to turn those 4 steps into functions that I can call and use. I'll link my code here: http://pastebin.com/TDb4WprL  I know it might be a little messy but I'm very short on time. I believe I have one function correct that I got some help with. One for displaying the numbers but when I tried to call it in my program (I tested it in a separate program on it's own) I kept getting a too few arguments error. I'll post that function below. Anyways any help would be greatly appreciated. 

 

 

void displayNums(const char* message, int *nums, int count) 

{
int i;
printf("%s", message);
for(i=0;i<count;++i)
{
printf("%d\n", nums[i]);
}
}

Link to comment
Share on other sites

Link to post
Share on other sites

So there are a few things that could help solve this.

 

Error line

The code that has the error in it (not the original code from your last thread :P)  It could be that you are calling the displayNums wrong

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

Yea I think I'm supposed to put something in displayNums(): when i call it. in the (). I just don't know what arguments to pass. Thats where I get lost. I understand how you created the function but as to calling it and passing arguments that stumps me. 

Link to comment
Share on other sites

Link to post
Share on other sites

Well I really agree with what @Ciccioo said in your previous thread.  You really need to learn before creating...e.g. in this case you need to learn how to figure out the arguments :P

 

Anyways here is the general concept behind reading this

void displayNums(const char* message, int *nums, int count)

 

displayNums is a function.  It returns void (ie nothing)

The parameters
1st: const char* message

2nd: int *nums

3rd: int count

 

So with message you need to pass in either a pointer or an array (in your case it would be something like "Hello")

num is taking a pointer or an array (in your case it is nums)

and count is the amount of items in nums (so again in your case it would be count)

 

...also as I said in the other thread, I gave an example of how to call it

displayNums("The numbers you entered are:\n", nums, count);

which would fit exactly into your code
 

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

I didn't realize that was an example of how to call it. It works now. I feel stupid. I'm actually currently taking a intro class to C in school atm. I just tend to struggle grasping the concepts. I'm really more of a hardware guy but I still want my CS degree

Link to comment
Share on other sites

Link to post
Share on other sites

I didn't realize that was an example of how to call it. It works now. I feel stupid. I'm actually currently taking a intro class to C in school atm. I just tend to struggle grasping the concepts. I'm really more of a hardware guy but I still want my CS degree

i think that your problem is not the struggle, it's the interest: as you're an hardware guy you don't really care about printing numbers on a boring black console

if you cared, you would have just googled about "c functions" and found the answer yourself in 5 minutes, just like you would have done if you needed to know something about g-sync, or broadwell, or 4k or maxwell or something

 

if you can't avoid c but you don't like it, maybe you can use a "workaround" learning something about javascript: it's kinda similar to C in the basic syntax, and stuff like functions is the same crap in every programming language anyway, but with javascript you can have a bit more fun and see more gorgeous results faster than C, maybe this will make you like coding more

 

remember: programmers get all the ladies

nope

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

×