c++ - error: incompatible types in assignment of 'char*' to 'char [4000]' -


i've been trying solve easy problem, can't figure why program doesn't work. can me? if so, can explain me why doesn't work?

#include <iostream> #include <cstring> #include <fstream>  using namespace std; ifstream in("sirul.in"); ofstream out("sirul.out"); char a[4000]="a",b[4000]="b",aux[4000]; int main() { int n,i;  in>>n;  if(n==1)out<<"a";  if(n==2)out<<"b";  for(i=3;i<=n;i++)  {      aux=strcpy(aux,b);      b=strcat(b,a);      a=strcpy(a,aux);  }      return 0; } 

strcpy , strcat work directly on pointer pass in first argument, return can chain calls. such, assigning result destination pointer redundant. in case, it's invalid, can't reassign array.

the fix not assign return value of calls:

strcpy(aux,b); strcat(b,a); strcpy(a,aux); 

however, since using c++, should use std::string instead, gives nice value semantics string data.


Comments