Guest User

Untitled

a guest
Oct 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. /**
  2. ============================================================================
  3. Author : Eric Schneider
  4. Version : ver 1.0
  5. Description : Lab6
  6. ============================================================================
  7. */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11.  
  12.  
  13. #define MAX ???
  14. int main()
  15. {
  16. int num_seqs, i, row;
  17. int num_people = 10;
  18. int dna_length = 1000;
  19. char dna[num_people][dna_length];
  20. char people[num_people][100];
  21. char filename[] = "dna.txt";
  22.  
  23.  
  24. FILE* fp = fopen(filename, "r"); // try to open the file as Read-only
  25. if (fp == NULL)
  26. {
  27. printf("\nError opening the file '%s'. Terminating the program.\n", filename);
  28. return 1; // terminate the program with error code '1'
  29. }
  30.  
  31. i = 0; // while-loop to read up 'num_people' records from the DNA data file
  32. while(i<num_people && fgets(dna[i], dna_length, fp) != NULL)
  33. {
  34. i = i + 1;
  35. }
  36.  
  37. if (i == 0) // terminate the program if no records were read from the DNA data file
  38. {
  39. printf("\nError reading from the file '%s'. Terminating the program.\n", filename);
  40. return 2; // terminate with error code 2
  41. }
  42.  
  43.  
  44. printf("\nSuccessfully read %i records from the DNA data file '%s'.\n\n", i, filename);
  45.  
  46. /**
  47. * Ask for input to get each persons name
  48. * and the DNA sequences of interest for each person
  49. */
  50. row = 0;
  51. //one name per row and go until we have the number people
  52. while(row < num_people)
  53. {
  54. // Get the name of person i
  55. printf("Please enter the name of person %i: ",row+1);
  56. scanf("%[^\n]s", &people[row][0]); // scanf() to allow for space in the input strings
  57. fflush(stdin); // Clear keyboard buffer
  58. printf("name = '%s'\n", &people[row][0]);
  59. row = row + 1;
  60.  
  61.  
  62. printf("How many genetic sequences are you interested in? ");
  63. scanf(" %i", &num_seqs);
  64. fflush(stdin); // Clear keyboard buffer
  65.  
  66.  
  67. }
  68. /** YOUR WORK GOES BELOW HERE **/
  69.  
  70. char str[num_seqs][20]; // create a 2D char array with 5 rows and 80 columns
  71. char strchr[num_seqs][20]; // create a char vector holding 80 characters
  72. int trait, result; // int variables idx (offset to our arrays) and result
  73.  
  74. trait = 0;
  75. while (trait < num_seqs)
  76. {
  77. sprintf(&str[trait][0], "Line %i", trait+1);
  78. printf("\n '%s'", &str[trait][0]);
  79. char str[trait][0], strTest;
  80. result = strchr[trait][0], strchr;
  81.  
  82. if (result < 0)
  83. {
  84. printf("\n'%s' is less than '%s'", str[trait][0], strTest);
  85. }
  86. else if (result > 0)
  87. {
  88. printf("\n'%s' is greater than '%s'", str[trait][0], strTest);
  89. }
  90. else if (result == 0)
  91. {
  92. printf("\n'%s' is equal to '%s'", str[trait][0], strTest);
  93. }
  94.  
  95. trait++; //The while loop will reach the end
  96. }
  97.  
  98.  
  99.  
  100.  
  101. /***END OF THIS PROGRAM***/
  102. printf("\n\nDone!\n");
  103. return 0;
  104. }
  105.  
  106. /** int strcmp(const char *interest1, const char );**/
Add Comment
Please, Sign In to add comment