이런 에러가 나는데 왜그런걸까요??

test.cpp: In function 'int main()':
test.cpp:11:29: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
           if(strcmp(arr[i][j], 'F')==0) res++;
                             ^
In file included from test.cpp:2:0:
c:\mingw\include\string.h:77:38: note:   initializing argument 1 of 'int strcmp(const char*, const char*)'
 _CRTIMP __cdecl __MINGW_NOTHROW  int strcmp (const char *, const char *) __MINGW_ATTRIB_PURE;
                                      ^
test.cpp:11:35: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
           if(strcmp(arr[i][j], 'F')==0) res++;
                                   ^
In file included from test.cpp:2:0:
c:\mingw\include\string.h:77:38: note:   initializing argument 2 of 'int strcmp(const char*, const char*)'
 _CRTIMP __cdecl __MINGW_NOTHROW  int strcmp (const char *, const char *) __MINGW_ATTRIB_PURE;
                                      ^
test.cpp:16:29: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
           if(strcmp(arr[i][j], 'F')==0) res++;
                             ^
In file included from test.cpp:2:0:
c:\mingw\include\string.h:77:38: note:   initializing argument 1 of 'int strcmp(const char*, const char*)'
 _CRTIMP __cdecl __MINGW_NOTHROW  int strcmp (const char *, const char *) __MINGW_ATTRIB_PURE;
                                      ^
test.cpp:16:35: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
           if(strcmp(arr[i][j], 'F')==0) res++;
                                   ^
In file included from test.cpp:2:0:
c:\mingw\include\string.h:77:38: note:   initializing argument 2 of 'int strcmp(const char*, const char*)'
 _CRTIMP __cdecl __MINGW_NOTHROW  int strcmp (const char *, const char *) __MINGW_ATTRIB_PURE;
                                      ^

seico75   6년 전

arr[i][j]와 'F' 는 char 이고 strcmp 는 const char * 를 원하기 때문에 에러가 생깁니다.

하시고자 하는 것은 문자 비교이고 strcmp 는 문자열(문자들의 연속)을 하기 때문에 적합하지 않습니다.

그냥 strcmp( ...) == 0 을 arr[i][j] == 'F' 로 하시면 됩니다.

댓글을 작성하려면 로그인해야 합니다.