2

I'm making a program that takes a three-digit integer and splits it into two integers. 224 would become 220 and 4. 114 would become 110 and 4.

Basically, you do it with modulos. I wrote what I think should work and the compiler keeps saying that there is a missing parenthesis before the &big but any changes just make more errors happen.

#include <stdio.h>

void split_num(int complete, int *big, int *little){
     *little = complete%10;
     *big  = complete - *little;
     return;
}


int main()
{
    int complete, big, little;

    printf("Give an integer to split: \n");
    scanf("%d", &complete);

    void split_num(complete, &big, &little);
    printf("Num split into 2 is : %d and %d", big, little);

    return 0;
}
2
  • it looks like you don't want the word void before split_num when you call it in main. see what happens if you remove that Commented Oct 21, 2011 at 21:26
  • interested on the fix of this... still learning pointers my self. Commented Oct 21, 2011 at 21:27

4 Answers 4

3

Take out the "void" in your call to split_num(). It's only used in the function declaration (to signify that it does not return a value), not in actual invocations of it.

Sign up to request clarification or add additional context in comments.

Comments

0

The line (in main())

void split_num(complete, &big, &little);

should read

split_num(complete, &big, &little);

Comments

0

remove the void in the line "void split_num". You don't specify return values (void) when just calling a method.

Comments

0

You have an error in the following line:

void split_num( complete, &big, &little );

Remove the void return type and invoke the function like so:

split_num( complete, &big, &little );

The return; statement in the split_num( ... ) function is also unnecessary.

2 Comments

can you give me an example of when a function would not be "void" and would need to return a number? thanks for telling me to remove the void i'm so happy it works!
@Arthur What you are referring to is the function return type. When a function has a void return type it does not return anything. An example of a function that returns an integer would be int main() which returns zero if your C program executes successfully otherwise non-zero.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.