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?