0

The commands will be in the form:

command filename bytes\nfile_contents

I'm having no trouble separating ADD, filename, and the number of bytes, but I am not sure how I can get the remainder of the server command, namely the file contents.

This is how I am parsing each command. Currently to get the file contents I am getting the left most char* that is '\n'. the file_contents char* never changes from NULL.

command = strtok( message, " \n" );
file = strtok( NULL, " " );
bytes = atoi( strtok( NULL, "\n" ) );
file_contents = strchr( message, '\n' );

Any suggestions for how to get the file contents?

4

1 回答 1

0

我会做

command = strtok( message, " \n" );
file = strtok( NULL, " " );
bytestr = strtok( NULL, "\n" );
bytes = atoi( bytestr );
file_contents = bytestr + strlen(bytestr) + 1;

假设file_contentsbytestr都是char *

于 2014-11-14T21:50:15.490 回答