-1
我需要使用fgets讀入文件的函數的幫助。我們已經給出了該功能應該做什麼的描述,所以我沒有做到這一點,但它仍然無法正常工作。我在這裏先向您的幫助表示感謝。使用fgets在文件中讀取
typedef struct StringArray_ {
char **strings;
int size;
}StringArray;
void create_commands_tree(Command **commands, const char *file);
void insert_into_commands_tree(Command** node, char** data);
StringArray* tokenizer (char *string, const char* delimiters);
void create_commands_tree(Command **commands, const char *file) {
FILE *input;
input = fopen(file, "r");
char strings[256];
StringArray *temp;
while(fgets(strings,100,input)){
temp = tokenizer(strings, "\n");
}
insert_into_commands_tree(temp, temp->strings);
}
功能的描述是這樣的:
Reads from a file the game commands the checker uses instead of using fscanf you
are required to use fgets to read in an line of characters(a string including the
newline character and the adds the null terminator) into a local buffer. That local
buffer will be passed to our tokenizer function that will split the string passed into an
array of strings based off our passed in delimiters. The delimiters that we are using
are 「,\n」. Pass the returned StringArray structure’s field strings to the
insert_into_commands_tree with the commands double pointer.
,我要讀的文件是
pickup,2
help,1
quit,1
load,2
你還沒有說過什麼問題,甚至問了一個具體的問題? –
我是否正確地使用fgets? –
當然 - 但是是什麼讓你覺得'fgets'是問題所在? –