Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int ** tapologyArray;
- int stationsCount=0;
- void initTapologyArray(){
- int i=0;
- tapologyArray = (int**)malloc(stationsCount*sizeof(int*));
- for(i=0; i< stationsCount; i++)
- tapologyArray[i] = (int*)malloc(stationsCount*sizeof(int));
- }
- int main(){
- int i=0, j=0;
- char tapString[256];
- char tempc;
- int curStationID = -1;
- int temp;
- printf("Please enter number of stations:");
- scanf("%d", &stationsCount);
- getchar();
- initTapologyArray();
- printf("Please describe the network topology:\n");
- gets(tapString);
- for(i=0; i < strlen(tapString); i++){
- if(tapString[i] == ';'){ curStationID = -1; continue; }
- if(tapString[i] == ' ') continue;
- if (curStationID < 0) {
- tempc = tapString[i];
- temp = atoi(tapString[i]);
- curStationID = temp;
- continue;
- }
- tapologyArray[curStationID][i]=1;
- tapologyArray[i][curStationID]=1;
- }
- for(i=0; i < stationsCount; i++){
- printf("Row %d: ", i);
- for(j=0; j < stationsCount; j++)
- printf("Col %d", j);
- printf("\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment