Guest User

Untitled

a guest
Dec 30th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Ponto
  5. {
  6. float x;
  7. float y;
  8. struct ponto *prox;
  9. };
  10.  
  11. typedef struct Ponto ponto;
  12.  
  13. void inicia_lista(ponto *lista)
  14. {
  15. lista->prox = NULL;
  16. }
  17.  
  18. void auxiliar(ponto *lista, int i)
  19. {
  20. FILE *fp;
  21. fp=fopen("dados", "r");
  22.  
  23. ponto *novo=(ponto*) malloc(sizeof(ponto));
  24.  
  25. char linha[100];
  26.  
  27. ponto *tmp=lista;
  28. while(tmp->prox != NULL)
  29. {
  30. tmp=tmp->prox;
  31. }
  32.  
  33. tmp->prox=novo;
  34.  
  35. while(i>0)
  36. {
  37. fgets(linha, 100, fp);
  38. i--;
  39. }
  40.  
  41. fscanf(fp, "%f %f \n", &novo->x, &novo->y);
  42. printf("%f %f \n", novo->x, novo->y);
  43. sleep(1);
  44. fclose(fp);
  45. }
  46.  
  47. void le_ficheiro(ponto *lista)
  48. {
  49. sleep(1);
  50. FILE *fp;
  51. fp=fopen("dados", "r");
  52.  
  53. FILE *ficheiro;
  54. ficheiro=fopen("linhas", "r");
  55. int a, i=1;
  56. fscanf(ficheiro, "%i", &a);
  57. fclose(ficheiro);
  58.  
  59. char linha[100];
  60. fgets(linha, 100, fp);
  61.  
  62. ponto *novo=(ponto*) malloc(sizeof(ponto));
  63. lista->prox=novo;
  64.  
  65. fscanf(fp, "%f %f \n", &novo->x, &novo->y);
  66. printf("%f %f \n", novo->x, novo->y);
  67. sleep(1);
  68. fclose(fp);
  69. while(i<a)
  70. {
  71. i++;
  72. auxiliar(lista, i);
  73. }
  74. }
  75.  
  76. int main()
  77. {
  78. ponto *lista=(ponto*) malloc(sizeof(ponto));
  79. inicia_lista(lista);
  80. le_ficheiro(lista);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment