if(init()==-1) exit(1); while(1) { adata=analogRead(0); printf("analog read %d\n",adata); if(adata==-1) printf("IO Error"); } return 1; }
time_t start, end; double elapsed; // seconds start = time(NULL); int terminate = 1; //Exit on failure to start communications with the GrovePi while (terminate) { end = time(NULL); elapsed = difftime(end, start); if (elapsed >= 1.0 /* seconds */) terminate = 0; else // No need to sleep when 90.0 seconds elapsed. usleep(50000); }
GNU nano 2.2.6 File: analogcurrentsensor.c Modified // GrovePi Example for using the analog read. // http://dexterindustries.com/grovepi #include <GrovePi.h> int main(void) { int adata; time_t start, end; double elapsed; // seconds start = time(NULL); int terminate = 1; //Exit on failure to start communications with the GrovePi while (terminate) { end = time(NULL); elapsed = difftime(end, start); if (elapsed >= 1.0 /* seconds */) terminate = 0; else // No need to sleep when 90.0 seconds elapsed. usleep(50000); } if(init()==-1) exit(1); while(1) { adata=analogRead(0); printf("analog read %d\n",adata); if(adata==-1) printf("IO Error"); } return 1; }
if(init()==-1) exit(1); while(1) { adata=analogRead(0); printf("analog read %d\n",adata); if(adata==-1) printf("IO Error"); } return 1; }
time_t start, end; double elapsed; // seconds start = time(NULL); int terminate = 1; //Exit on failure to start communications with the GrovePi while (terminate) { end = time(NULL); elapsed = difftime(end, start); if (elapsed >= 1.0 /* seconds */) terminate = 0; else // No need to sleep when 90.0 seconds elapsed. usleep(50000); }
GNU nano 2.2.6 File: analogcurrentsensor.c Modified // GrovePi Example for using the analog read. // http://dexterindustries.com/grovepi #include <GrovePi.h> int main(void) { int adata; time_t start, end; double elapsed; // seconds start = time(NULL); int terminate = 1; //Exit on failure to start communications with the GrovePi while (terminate) { end = time(NULL); elapsed = difftime(end, start); if (elapsed >= 1.0 /* seconds */) terminate = 0; else // No need to sleep when 90.0 seconds elapsed. usleep(50000); } if(init()==-1) exit(1); while(1) { adata=analogRead(0); printf("analog read %d\n",adata); if(adata==-1) printf("IO Error"); } return 1; }
terminate = 1; while (terminate) { ... if (xx) terminate = 0; }
if (elapsed >= 1.0 /* seconds */) { ... }
void getAge(char *age, unsigned long int size){ printf("Enter age, maximum age is 9999: "); fgets(age, size, stdin); checkQuit(age); int length =stLen(age); if(length==0 || (length==1 && age[0]=='0')){ //Special first case not covered by below printf("Wrong format of age.\n"); getAge(age, size); } if(5>length>0){ //Length check, less than five and not 0. for (size_t i = 0; i < length; i++) { //Check all characters ascii value for digits. if(age[i]>57 || age[i]<48){ // If we find one thats not a digit, start over. printf("Wrong format of age. Ascii\n"); getAge(age, size); } } }else{ printf("Wrong format of age. Length\n"); getAge(age, size); } }
void getAge(char *age, unsigned long int size){ printf("Enter age, maximum age is 9999: "); fgets(age, size, stdin); checkQuit(age); int length =stLen(age); if(length==0 || (length==1 && age[0]=='0')){ //Special first case not covered by below printf("Wrong format of age.\n"); getAge(age, size); } if(5>length>0){ //Length check, less than five and not 0. for (size_t i = 0; i < length; i++) { //Check all characters ascii value for digits. if(age[i]>57 || age[i]<48){ // If we find one thats not a digit, start over. printf("Wrong format of age. Ascii\n"); getAge(age, size); } } }else{ printf("Wrong format of age. Length\n"); getAge(age, size); } }
void extractWord(char *word, char **store){ int length = strlen(word); if(length==0 || word==NULL){ return; } for(int i = 0; i<length; i++){//Loop over string, return pointer to start of actual word if(word[i]<91 && word[i]>64){ *store = (word+i); //Store location of how far we iterated } } } int main(){ int counter = 0; FILE *fpb = fopen("bats.txt", "a+"); char *tmpStore = calloc(1, 20); char *tmpWord = calloc(1, 20); while(fgets(tmpStore, 20, fpb)){ //extractWord(tmpStore, &tmpWord); printf("%s", tmpStore); } return 0; }
void extractWord(char *word, char **store){ int length = strlen(word); if(length==0 || word==NULL){ return; } for(int i = 0; i<length; i++){//Loop over string, return pointer to start of actual word if(word[i]<91 && word[i]>64){ *store = (word+i); //Store location of how far we iterated } } } int main(){ int counter = 0; FILE *fpb = fopen("bats.txt", "a+"); char *tmpStore = calloc(1, 20); char *tmpWord = calloc(1, 20); while(fgets(tmpStore, 20, fpb)){ //extractWord(tmpStore, &tmpWord); printf("%s", tmpStore); } return 0; }
Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!
Swish: 123 536 99 96 Bankgiro: 211-4106
Flashback finansieras genom donationer från våra medlemmar och besökare. Det är med hjälp av dig vi kan fortsätta erbjuda en fri samhällsdebatt. Tack för ditt stöd!
Swish: 123 536 99 96 Bankgiro: 211-4106