9
votes
void
argmatch_valid (const char *const *arglist,
            const char *vallist, size_t valsize)
{
  size_t i;
  const char *last_val = NULL;

  fprintf (stderr, _("Valid arguments are:"));
  for (i = 0; arglist[i]; i++)
    if ((i == 0)|| memcmp (last_val, vallist + valsize * i, valsize))
    {
      fprintf (stderr, "\n  - `%s'", arglist[i]);
      last_val = vallist + valsize * i;
    }
    else
    {
      fprintf (stderr, ", `%s'", arglist[i]);
    }
  putc ('\n', stderr);
}

I am getting the following although I have included stdio.h in my .c file

warning C4013: 'fprintf' undefined; assuming extern returning int

error C2065: 'stderr' : undeclared identifier

warning C4013: 'putc' undefined; assuming extern returning int

I thought of disabling the warning by #pragma warning( disable :4013 ) but wanted to compile the code clean.

Thanks in advance

1
I keep on wondering... The OP knows about pragmas but not about stdio.h - SomeWittyUsername
@icepack I am getting the following although I have included stdio.h in my .c file - Capricorn
I have already included stdio.h - Capricorn
You have an invalid character: _ in fprintf (stderr, _("Valid arguments are:"));. Remove it - SomeWittyUsername
@Abhineet I have referrred msdn already. Also, saw on codepad, it compiles fine. I am suspecting the error elsewhere as icepack. Here is the code codepad.org/Lv6fLeIH#line-19 - Capricorn

1 Answers

12
votes

While stdio.h should work, sometimes you need to include stdlib.h as well. Include the following:

#include <stdio.h>
#include <stdlib.h>

Declare both of these includes at the TOP of the same .C file your argmatch_valid function above is defined.

My crystal ball suggests that the stdio.h you think you are including is getting wrapped by a comment or within another preprocessor section that is getting wiped out. Maybe you can post your entire source file. Someone will likely spot the real error.