Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. void scanLab(Labirinto *l, int m, int n)
  2. {
  3. int i;
  4. /*possível ocorrência da entrada ou saída em alguma linha*/
  5. char *ocu_in, *ocu_out;
  6.  
  7. char *tmp = (char *)malloc((n+1) * sizeof(char));
  8.  
  9. l->m = m;
  10. l->n = n;
  11.  
  12. /*Aloca o array de ponteiros para arrays de caractres*/
  13. l->matriz = (char **)malloc(m*sizeof(char));
  14.  
  15. /*Aloca e lê as linhas individuais*/
  16. for(i=0; i<m; i++)
  17. {
  18. *(l->matriz+i) = (char *)malloc((n+1)*sizeof(char));
  19. scanf("%s", tmp);
  20.  
  21. ocu_in = strchr(tmp, 'e');
  22. ocu_out = strchr(tmp, 's');
  23.  
  24. /*Encontrou entrada ou saída*/
  25. if(ocu_in)
  26. {
  27. l->in.i = i;
  28. l->in.j = ocu_in - tmp;
  29. ocu_in = NULL;
  30. }
  31. else if(ocu_out)
  32. {
  33. l->out.i = i;
  34. l->out.j = ocu_out - tmp;
  35. ocu_out = NULL;
  36. }
  37. strcpy(*(l->matriz+i), tmp);
  38. }
  39. free(tmp);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement