Advertisement
veto14

Q7Exercicios1

Mar 28th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int ultima_ocorrencia(char *s,char c);
  6.  
  7. int main(void){
  8.     char cadeia[50],spec;
  9.     scanf("%c\n",&spec);
  10.     int last;
  11.     fgets(cadeia,50,stdin);
  12.     last = ultima_ocorrencia(cadeia,spec);
  13.     printf("Ultima ocorrencia: %d\n",last);
  14. }
  15.  
  16. int ultima_ocorrencia(char *s,char c){
  17.     int len,i,l_oc = -1;
  18.     len = strlen(s) - 1;
  19.     for(i=0;i<len;i++){
  20.         if(s[i] == c){
  21.             l_oc = i;
  22.         }
  23.     }
  24.     return l_oc;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement