Guest User

Untitled

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int ** tapologyArray;
  6. int stationsCount=0;
  7.  
  8.  
  9. void initTapologyArray(){
  10.  
  11.     int i=0;
  12.  
  13.     tapologyArray = (int**)malloc(stationsCount*sizeof(int*));
  14.     for(i=0; i< stationsCount; i++)
  15.         tapologyArray[i] = (int*)malloc(stationsCount*sizeof(int));
  16.  
  17. }
  18.  
  19. int main(){
  20.     int i=0, j=0;
  21.  
  22.     char tapString[256];
  23.  
  24.     char tempc;
  25.  
  26.     int curStationID = -1;
  27.     int temp;
  28.  
  29.     printf("Please enter number of stations:");
  30.     scanf("%d", &stationsCount);
  31.     getchar();
  32.  
  33.     initTapologyArray();
  34.  
  35.     printf("Please describe the network topology:\n");
  36.     gets(tapString);
  37.  
  38.  
  39.     for(i=0; i < strlen(tapString); i++){
  40.  
  41.         if(tapString[i] == ';'){ curStationID = -1; continue; }
  42.         if(tapString[i] == ' ') continue;
  43.  
  44.         if (curStationID < 0) {
  45.             tempc = tapString[i];
  46.             temp = atoi(tapString[i]);
  47.             curStationID = temp;
  48.             continue;
  49.         }
  50.  
  51.         tapologyArray[curStationID][i]=1;
  52.         tapologyArray[i][curStationID]=1;
  53.  
  54.     }
  55.  
  56.     for(i=0; i < stationsCount; i++){
  57.         printf("Row %d: ", i);
  58.         for(j=0; j < stationsCount; j++)
  59.             printf("Col %d", j);
  60.  
  61.         printf("\n");
  62.     }
  63.  
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment