Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. struct Dictionary{
  4. char strings[1000][50];
  5. int n; // real size of array
  6. };
  7.  
  8. bool twoStrings(char *string1, char *string2){
  9. if (strlen(string1) < strlen(string2)){
  10. return false;
  11. }
  12. else {
  13. int k = 0;
  14. while (k < strlen(string1)){
  15. if (string1[k] != string2[k]){
  16. return false;
  17. }
  18. k = k + 1;
  19. }
  20. return true;
  21. }
  22. }
  23.  
  24. void stringThatStartsWithS(Dictionary *a, char *string){
  25. int k = 0;
  26. while (k < (*a).n){
  27. if (twoStrings((*a).strings[k], string) == true){
  28. printf("%s\n",(*a).strings[k]);
  29. }
  30. k = k + 1;
  31. }
  32. }
  33.  
  34. int main() {
  35. Dictionary a;
  36. a.n = 5;
  37. int k = 0;
  38. while (k < a.n){
  39. printf("Print string in massive");
  40. scanf("%s", a.strings[k]);
  41. k = k + 1;
  42. }
  43. char string[50];
  44. printf("Write 2st string\n");
  45. scanf("%s",string);
  46. stringThatStartsWithS(&a, string);
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement