Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5. int findpos(char s[], char c) ;
  6. char string[80], ch ;
  7. int y = 0 ;
  8. std::cout << "Enter a string value maximum of (80): " ;
  9. std::cin.getline(string, 80) ;
  10. std::cout << "Enter a char to be seacrched for: " ;
  11. std::cin.get(ch) ;
  12. y = findpos(string, ch);
  13. if (y == -1)
  14. std::cout << "Sorry, character is not a string.";
  15. return 0;
  16. }
  17. int findpos(char s[], char c)
  18. {
  19. int flag = -1 ;
  20. for (int i = 0; s[i] != ''; i++)
  21. {
  22. if (s[i] == c)
  23. {
  24. flag = 0;
  25. std::cout << "The char in the string is at position: " << i + 1 << std::endl;
  26. }
  27. }
  28. return flag;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement