Advertisement
Guest User

ex2-5-1.c

a guest
May 26th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define LIMIT 1024
  4.  
  5. int any(char s1[], char s2[]);
  6. void getline(char s[], int lc);
  7.  
  8. /* Exercise 2-5. Write the function any(s1,s2), which returns the first location in a string s1
  9. where any character from the string s2 occurs, or -1 if s1 contains no characters from s2.
  10. (The standard library function strpbrk does the same job but returns a pointer to the
  11. location.) */
  12. main()
  13. {
  14.     char str1[LIMIT], str2[LIMIT];
  15.     int lc;
  16.     lc = 0;
  17.    
  18.     getline(str1, lc);
  19.     getline(str2, lc);
  20.    
  21.     printf("%s %d\n", str1, lc);
  22.     printf("%s %d\n", str2, lc);
  23. }
  24.  
  25. /* getline: gets the character input and convert it into a string. */
  26. void getline(char s[], int lc)
  27. {
  28.     int c, i, lim;
  29.    
  30.     lim = LIMIT;
  31.     i = 0;
  32.    
  33.     printf("String %d: ", lc);
  34.     while (lim > 0) {
  35.         c = getchar();
  36.         if (c == '\n' || c == EOF) {
  37.             lim = 0;
  38.         }
  39.         else {
  40.             s[i] = c;
  41.             ++i;
  42.         }
  43.     }
  44.     ++lc;
  45.     s[i] = '\0';
  46. }
  47.  
  48. /* any: returns the first location of the occurring character of s2 in s1 */
  49. int any(char s1[], char s2[])
  50. {
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement