Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct vertex
  6. {
  7. int x,y,cost;
  8. char name;
  9. struct vertex* edges[10];
  10.  
  11. }node;
  12.  
  13. int main()
  14. {
  15. char ch, file_name[25],data[10000];
  16. FILE *fp;
  17.  
  18. //printf("Enter name of a input file\n");
  19. //gets(file_name);
  20. fp = fopen("data.txt", "r"); // read mode
  21.  
  22. if (fp == NULL)
  23. {
  24. perror("Error while opening the file.\n");
  25. exit(EXIT_FAILURE);
  26. }
  27. int nodes_count,edges_count;
  28. char init,fin;
  29. fscanf(fp,"%i %i\n",&nodes_count,&edges_count);
  30. fscanf(fp,"%c %c\n",&init,&fin);
  31. //printf("%d %d %c %c",a,b,c,d);
  32. node* nodes[10];
  33.  
  34. //creating nodes
  35. for(int i=0; i<nodes_count;i++)
  36. {
  37. nodes[i] = (node*)malloc(sizeof(node));
  38. int x,y;
  39. char n;
  40. fscanf(fp,"%d %d %c\n",&x,&y,&n);
  41. nodes[i]->name = n;
  42. nodes[i]->x = x;
  43. nodes[i]->y = y;
  44. }
  45. //printf("%d %d %c\n",nodes[7]->x,nodes[7]->y,nodes[7]->name);
  46. int decode(char n)
  47. {
  48. for(int i = 0; i < nodes_count;i++)
  49. if(nodes[i]->name == n)
  50. return i;
  51. }
  52. //creating edges
  53. for(int i=0; i < edges; i++)
  54. {
  55. int index=0,cost;
  56. char from,to;
  57.  
  58. }
  59.  
  60. fclose(fp);
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement