it crashes after it prints out the the script from the file word by word
Code:
/* Reading from the script file */
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <ctype.h>
//#include <iostream>
#include <string.h>
//#include "DLPORTIO.h"
int main()
{
FILE *myFile;
char filename[20];
int time[10] = {1,2,3,4,5,6,7,8,9,10};
char data[50];
char *token;
/* Ask user to enter the filname including the format */
printf( "Enter the script filename with the format. ie script.txt\n" );
scanf( "%s", filename );
/* Open filename for Reading (only) */
myFile = fopen(filename, "r");
if (myFile == NULL) {
printf("ERROR! Unable to open your file.\n");
printf( "Closing file in 2 seconds.......\n" );
//delay two second
sleep (2000);
exit(-1);
}
/* Open file success message */
else {
printf( "The script file %s is being read....\n\n", filename );
}
fgets (data , 50 , myFile);
token = strtok( data , " " );
while ( token != NULL )
{
printf( "%s\n", token );
token = strtok( NULL, " " );
}
//I GUESS IT CRASHES HERE?
//token=toupper(token);
if ( strcmp ( token, "RESET" )==0 ) {
printf( "Resetting the motor ......");
//outportb(0x378, 0x00);
}
else if ( strcmp ( token, "#" )== 0 ){
printf( "Skipped..");
sleep (500);
exit(-1);
}
else if ( strcmp ( token, "FORWARD" )==0 ) {
printf( "Moving forward.......");
//outportb(0x378, 0x01);
}
else if ( strcmp ( token, "REVERSE" )==1 ) {
//outportb(0x378, 0x01);
}
else if ( strcmp ( token, "PAUSE" )==1 ) {
//outportb(0x378, 0x01);
}
else if ( strcmp ( token, "HEADLIGHTS" )==1 ) {
//outportb(0x378, 0x01);
}
else if ( strcmp ( token, "TURNRIGHT" )==1 ) {
//outportb(0x378, 0x01);
}
else if ( strcmp ( token, "TURN LEFT" )==1 ) {
//outportb(0x378, 0x01);
}
else if ( strcmp ( token, "LOOP" )==1 ) {
//outportb(0x378, 0x01);
}
else if ( strcmp ( token, "ENDLOOP" )==1 ) {
//outportb(0x378, 0x01);
}
getch();
return 0;
}