I'm new to C and feel as if I'm missing some formatting syntax but I can't figure out what exactly. Upon compiling the program with
gcc -o test test.c myprintf.c
I get the following error
expected â;â, â,â or â)â before âsâ
I'm sorry if this is some simple overlook on my part, but the format seems to be correct to me. Also this is part of a homework assignment however I tested every function I was responsible for creating separately and they work just fine. I'm omitting the functions I was responsible for writing, if you believe they are needed I will edit them in as it appears to not even access them. The error occurs directly between my first and section function (the blank line between printint and printstring.
Simplest test file possible — test.c
#include <stdio.h>
extern void myprintf(const char *, ...);
int main()
{
myprintf("Nothing much\n");
return 0;
}
myprintf.c
#include <stdarg.h>
#include <stdio.h>
void printint(int i){
int temp;
/*some while loop that shrinks i while outputting the correct char*/
int ascii = i + '0';
putchar(ascii);
}
void printstring(char[] s){
int i = 0;
/*some while loop that moves through a string using putchar to output the corresponding character*/
}
void printhex(int k){
/*long complicated program involving a series of loops that change a decimal into a hexidecimal, obviously without using any built in printf or modifiers*/
}
/*This is the code provided that uses my 3 functions. I assume it all to be correct*/
void myprintf(const char *fmt, ...) {
const char *p;
va_list argp;
int i;
char *s;
va_start(argp, fmt);
for (p = fmt; *p != '\0'; p++) {
if (*p != '%') {
putchar(*p);
continue;
}
switch (*++p) {
case 'c':
i = va_arg(argp, int);
putchar(i);
break;
case 'd':
i = va_arg(argp, int);
printint(i);
break;
case 's':
s = va_arg(argp, char *);
printstring(s);
break;
case 'x':
i = va_arg(argp, int);
printhex(i);
break;
case '%':
putchar('%');
break;
}
}
va_end(argp);
}