Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ============================================================================
- Author : Eric Schneider
- Version : ver 1.0
- Description : Lab6
- ============================================================================
- */
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #define MAX ???
- int main()
- {
- int num_seqs, i, row;
- int num_people = 10;
- int dna_length = 1000;
- char dna[num_people][dna_length];
- char people[num_people][100];
- char filename[] = "dna.txt";
- FILE* fp = fopen(filename, "r"); // try to open the file as Read-only
- if (fp == NULL)
- {
- printf("\nError opening the file '%s'. Terminating the program.\n", filename);
- return 1; // terminate the program with error code '1'
- }
- i = 0; // while-loop to read up 'num_people' records from the DNA data file
- while(i<num_people && fgets(dna[i], dna_length, fp) != NULL)
- {
- i = i + 1;
- }
- if (i == 0) // terminate the program if no records were read from the DNA data file
- {
- printf("\nError reading from the file '%s'. Terminating the program.\n", filename);
- return 2; // terminate with error code 2
- }
- printf("\nSuccessfully read %i records from the DNA data file '%s'.\n\n", i, filename);
- /**
- * Ask for input to get each persons name
- * and the DNA sequences of interest for each person
- */
- row = 0;
- //one name per row and go until we have the number people
- while(row < num_people)
- {
- // Get the name of person i
- printf("Please enter the name of person %i: ",row+1);
- scanf("%[^\n]s", &people[row][0]); // scanf() to allow for space in the input strings
- fflush(stdin); // Clear keyboard buffer
- printf("name = '%s'\n", &people[row][0]);
- row = row + 1;
- printf("How many genetic sequences are you interested in? ");
- scanf(" %i", &num_seqs);
- fflush(stdin); // Clear keyboard buffer
- }
- /** YOUR WORK GOES BELOW HERE **/
- char str[num_seqs][20]; // create a 2D char array with 5 rows and 80 columns
- char strchr[num_seqs][20]; // create a char vector holding 80 characters
- int trait, result; // int variables idx (offset to our arrays) and result
- trait = 0;
- while (trait < num_seqs)
- {
- sprintf(&str[trait][0], "Line %i", trait+1);
- printf("\n '%s'", &str[trait][0]);
- char str[trait][0], strTest;
- result = strchr[trait][0], strchr;
- if (result < 0)
- {
- printf("\n'%s' is less than '%s'", str[trait][0], strTest);
- }
- else if (result > 0)
- {
- printf("\n'%s' is greater than '%s'", str[trait][0], strTest);
- }
- else if (result == 0)
- {
- printf("\n'%s' is equal to '%s'", str[trait][0], strTest);
- }
- trait++; //The while loop will reach the end
- }
- /***END OF THIS PROGRAM***/
- printf("\n\nDone!\n");
- return 0;
- }
- /** int strcmp(const char *interest1, const char );**/
Add Comment
Please, Sign In to add comment