Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define LIMIT 1024
- int any(char s1[], char s2[]);
- void getline(char s[], int lc);
- /* Exercise 2-5. Write the function any(s1,s2), which returns the first location in a string s1
- where any character from the string s2 occurs, or -1 if s1 contains no characters from s2.
- (The standard library function strpbrk does the same job but returns a pointer to the
- location.) */
- main()
- {
- char str1[LIMIT], str2[LIMIT];
- int lc;
- lc = 0;
- getline(str1, lc);
- getline(str2, lc);
- printf("%s %d\n", str1, lc);
- printf("%s %d\n", str2, lc);
- }
- /* getline: gets the character input and convert it into a string. */
- void getline(char s[], int lc)
- {
- int c, i, lim;
- lim = LIMIT;
- i = 0;
- printf("String %d: ", lc);
- while (lim > 0) {
- c = getchar();
- if (c == '\n' || c == EOF) {
- lim = 0;
- }
- else {
- s[i] = c;
- ++i;
- }
- }
- ++lc;
- s[i] = '\0';
- }
- /* any: returns the first location of the occurring character of s2 in s1 */
- int any(char s1[], char s2[])
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement