
untested
Dependencies: SDFileSystem mbed
Revision 3:734f4f80832c, committed 2017-11-10
- Comitter:
- nnguyen45
- Date:
- Fri Nov 10 15:00:18 2017 +0000
- Parent:
- 2:1ee5d99a9bae
- Commit message:
- Working module to parse lesson plan!!!!
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Nov 10 02:48:53 2017 +0000 +++ b/main.cpp Fri Nov 10 15:00:18 2017 +0000 @@ -17,58 +17,35 @@ string word[1]; char check; string temp; - string tempword; + string tempword = ""; int counter = 0; FILE *fp = fopen("/sd/plan.txt", "r"); //create file - while (!feof(fp)) { // while not end of file - check = fgetc(fp); //grabs a char from file - while(check != '\n') { //while not at the end of line for letters - if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored - letter[counter] = temp; //write letter - counter = counter + 1; //increment counter - } else { - temp = check; //store letter - } - check = fgetc(fp); //grabs next char + if(fp == NULL) { + pc.printf("Could not open file for write\n"); + } + check = fgetc(fp); //grabs a char from file + while(check != '\n') { //while not at the end of line for letters + if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored + letter[counter] = temp; //write letter + pc.printf("Letter: %s \n", letter[counter]); + counter = counter + 1; //increment counter + } else { + temp = check; //store letter } - counter = 0; //reset counter check = fgetc(fp); //grabs next char - while(check != '\n') { //while not at the end of line for words - if((check == delimiter) && (tempword.length() != 0)) { //when at the comma at the end of a word - word[counter] = tempword; //write word - counter = counter + 1; //increment counter - } else { - tempword = tempword + check; //concatenate letters to build word - } - check = fgetc(fp); //grabs next char - } } - - - - - -/* - while (!feof(fp)) { // while not end of file - check = fgetc(fp); // get data from the file - pc.printf("%s", check); - if(check == '\n') { - counter = 0; - pc.printf("%s", check); - check = fgetc(fp); - tempword = check; - } else if(tempword.length() != 0) { - tempword = tempword + check; - } else if(check != delimiter) { - temp = check; - } else if((check == delimiter) && (temp.length() == 1)) { - letter[counter] = temp; - counter = counter + 1; + counter = 0; //reset counter + check = fgetc(fp); //grabs next char + while(!feof(fp)) { //while not at the end of line for words + if(check == delimiter) { //when at the comma at the end of a word + word[counter] = tempword; //write word + pc.printf("Word: %s \n", word[counter]); + tempword = ""; + counter = counter + 1; //increment counter } else { - word[counter] = tempword; - counter = counter + 1; + tempword = tempword + check; //concatenate letters to build word } - }*/ + check = fgetc(fp); //grabs next char + } fclose(fp); //close file - }