Arthur Collé
Arthur Collé

Reputation: 2607

c program, pointers

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;
}

Upvotes: 2

Views: 109

Answers (4)

Garee
Garee

Reputation: 1284

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.

Upvotes: 0

Edwin Buck
Edwin Buck

Reputation: 70909

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

Upvotes: 0

cli_hlt
cli_hlt

Reputation: 7164

The line (in main())

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

should read

split_num(complete, &big, &little);

Upvotes: 0

Chris Walton
Chris Walton

Reputation: 1346

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.

Upvotes: 3

Related Questions