int main(int argc, char *argv[])
{
FILE *inputFile = fopen(argv[1], "r");
char *line=NULL;
while(1) {
line = readLine(inputFile); //return file pointer
if (line == NULL)
break;
processCommand(line);
}
}
void processCommand(char *line){
char *command = NULL,char *hallName = NULL,char *movieName=NULL;
command = strtok(line," ");
if(command != NULL) {
if (strcmp(command,"CREATEHALL") == 0) {
hallName = strtok(NULL," ");
movieName = strtok(NULL," ");
if (hallName && movieName ) {
//printf("MovieName: %s - HallName: %s\n",movieName,hallName);
createHall(hallName,movieName);
}
}
}
void createHall(char* hallName,char* movieName) {
printf("MovieName: %s - HallName: %s\n",movieName,hallName);
//....
}
input.txt中
CREATEHALL“Red-Hall”“StarDust”
CREATEHALL“Orange-Hall”“Last_Samurai”
CREATEHALL“Blue-Hall”“London_has_fallen”
输出:
MovieName: "StarDust" - HallName: n
MovieName: "Last_Samurai" - HallName: n
MovieName: "London_has_fallen" - HallName:
当我删除命令行//printf("MovieName: %s - HallName: %s\n",movieName,hallName);
时,输出为:
MovieName: - HallName:
MovieName: - HallName:▒
MovieName:"Last_Samurai" - HallName:"Orange-Hall"
MovieName:"Last_Samurai" - HallName:▒
MovieName:"London_has_fallen" - HallName:"Blue-Hall"
MovieName:"London_has_fallen" - HallName:▒
为什么在processCommands函数中的printf会改变第二个printf的输出。为什么参数没有正确传递给createHall函数。
Linux中的这个问题。 Windows上没有问题。