Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to pass all the parameters of a function into another function in C

2 Answers

0 votes
#include <stdio.h>

typedef struct {
    char ch;
    int n;
    float f;
} Params;

void funcB(Params pr) {
    printf("%c\n", pr.ch);
    printf("%d\n", pr.n);
    printf("%.2f\n", pr.f);
}

void funcA(char ch, int n, float f) {
    Params pr;
    
    pr.ch = ch;
    pr.n = n;
    pr.f = f;

    funcB(pr);
}

int main(void) {
    funcA('z', 8900, 3.14f);
}

  
  
/*
run:

z
8900
3.14

*/

 



answered Aug 27, 2024 by avibootz
edited Aug 28, 2024 by avibootz
0 votes
#include <stdio.h>

typedef struct {
    char ch;
    int n;
    float f;
} Params;

void funcB(Params pr) {
    printf("%c\n", pr.ch);
    printf("%d\n", pr.n);
    printf("%.2f\n", pr.f);
}

void funcA(Params pr) {
    pr.f = pr.f * 2;

    funcB(pr);
}

void func() {
    Params pr = {'z', 8900, 3.14f};
    funcA(pr);
}

int main(void) {
    func();
}

  
  
/*
run:

z
8900
6.28

*/

 



answered Aug 28, 2024 by avibootz
...