I have a problem. The concept of Object Oriented Programming in C got homework. I need to use variadic functions. But I get a mistake. I'd appreciate it if you could help me. I'm new to encoding.
RastgeleKarakter.h :
#ifndef RASTGELEKARAKTER_H
#define RASTGELEKARAKTER_H
struct RASTGELEKARAKTER{
// code
};
RastgeleKarakter SKarakterOlustur(int...); // prototype
void Print(const RastgeleKarakter);
#endif
RastgeleKarakter.c :
#include "RastgeleKarakter.h"
#include "stdarg.h
RastgeleKarakter SKarakterOlustur(int... characters){
//code
}
Error :
make
gcc -I ./include/ -o ./lib/test.o -c ./src/Test.c
In file included from ./src/Test.c:3:0:
./include/RastgeleKarakter.h:17:38: error: expected ';', ',' or ')' before '...' token
RastgeleKarakter SKarakterOlustur(int...);
I don't know how many parameters there are. I want to solve this with the variable function.
The parameter list should not have a type nor a name
RastgeleKarakter SKarakterOlustur(int count, ...)
{
va_list args;
va_start(args, count);
int i = va_arg(args, int);
}
Use the macros defined in stdarg.h
header file to access the parameter list. further reading
If by your original deceleration, you meant that all members of the parameter list are integers, and since you will be supplying the count anyway, consider changing it to int count, int * list