Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "mdb.h"
  4. #include "mylist.h"
  5.  
  6. int main(int argc, char ** argv){
  7.  
  8. struct List thisList;
  9. initList(&thisList); //passing memeory address of list
  10.  
  11. argv++; //dont want name of program as input
  12.  
  13. if (*argv !=0){ //adding contents of database to linked list
  14.  
  15. char *x;
  16. x = calloc(1, sizeof(FILE));
  17.  
  18.  
  19. FILE *file;
  20. *file= argv[1];
  21. int i = 0;
  22.  
  23. while ((x[i] = getc(file)) != EOF){
  24.  
  25. addAfter(&thisList, x[i-1], x[i]);
  26. i++;
  27.  
  28. }//end while
  29.  
  30. }//end if
  31.  
  32. printf("What would you like to seach for?\n");
  33.  
  34. char *a;
  35. scanf("%c \n", a); //accept user input
  36.  
  37. char *search;
  38.  
  39. char *strncpy (char *search, * a, 5); //copies 5 characters from a into search
  40.  
  41. struct list *list_pointer = &thisList; //list pointer being used to traverse list
  42.  
  43. while(thisList !=0){//searching through the linked list
  44.  
  45. if(list_pointer->value == search){
  46. printf("%d\n", list_pointer->value);//print location of list_pointer
  47. printf("%c\n", list_pointer.value); //print value of list_pointer
  48. }//end if
  49.  
  50. list_pointer = list_pointer->next;//go onto next element
  51.  
  52.  
  53. }//end while
  54.  
  55. return 0;
  56.  
  57. }//end main function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement