too few arguments in invocation of macro "strcpy" - C VSCode

376 Views Asked by At

For some reason, the following code compiles and runs fine, but after adding the C/C++ VsCode extension, I get a syntax error saying that there are too few arguments.

For background, I am receiving a user input in main, passing the string to the this function, where I am tokenizing the string using " \n" as a delimiter, and each token represents a different "command". My goal here is to store each token in a different index to validate them, then pass the originally given string, input to a different function, since it needs to be passed as one value.

int login(int socket, char *input) {
    if (socket > 0 && input != NULL && strlen(input) > 0) {
        char buffer[MAX_LINE];
        strcpy(buffer, input);
        strtok(buffer, " \n");

Simplified (easily reproducible) version of what I'm trying to do:

header:

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

int func(char*);

main:

#include "str_test.h"
#define MAX_LINE 256 

int main(){
   char*str_input = NULL;
   char buff[MAX_LINE];
   fgets(str_input, MAX_LINE, stdin);
   strcpy(buff, str_input);

   func(buff);

   return 0;
}

int func(char*str){
   char new_buff[MAX_LINE];
   strcpy(new_buff, str);
   return 0; 
}

The exact error message is too few arguments in invocation of macro "strcpy"C/C++(54) on both instances of strcpy().

My Makefile C Flags are: set(CMAKE_C_FLAGS "-std=c11 -Wall -Wextra -Wshadow -Werror")

Is this because of a invalid compiler path(s)? Considering I haven't had any actual compilation or runtime errors?

1

There are 1 best solutions below

0
paulsm4 On

It sounds like you should probably ignore the "C/C++ VSCode extension" warning:

  • strcpy() takes two arguments: you don't have "too many arguments".
  • strcpy() is typically a function, not a "macro".
  • As you said: your code compiles and runs fine :)

SUGGESTION:

It's possible the VSCode extension warning is being triggered by something else, adjacent to your "strcpy()".

Consider reproducing the problem in a minimal, reproducible example. If you can reproduce it in a small, standalone test,then be sure to copy/paste the exact error text, and the line#.