-
Notifications
You must be signed in to change notification settings - Fork 0
/
atest.c
54 lines (44 loc) · 1.31 KB
/
atest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//I've been trying to figure out why I keep getting a segmentation default error in my code. It's supposed to receive a filename, read from it and parse the data into 3 different arrays. Any ideas?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINESIZE 80
#define data 98
// #define filename ATEST
int main(){
// FILE *data;
char line[LINESIZE];
// data = fopen(filename, "r");
if(data == NULL){
printf("error in accessing file specified \n");
exit(EXIT_FAILURE);
}
printf("access success\n");
int i = 0;
// while(fgets(line, sizeof line, data) != NULL){
while(data != NULL){
i++;
}
printf("Number of entries: %i \n", i);
// fclose(data);
printf("1\n");
// data = fopen(filename, "r\n");
printf("1\n");
char* transMAC[i];
char* recMAC[i];
int bytes[i];
int j = 0;
// while(fgets(line, sizeof line, data) != NULL){
while (data != NULL){
strtok(line, "\t");
strcpy(transMAC[j],strtok(NULL, "\t"));
strcpy(recMAC[j],strtok(NULL, "\t"));
bytes[j] = atoi(strtok(NULL, "\t"));
j++;
}
for(int k = 0; k < i; k++){
printf("%s ", transMAC[k]);
printf("%s ", recMAC[k]);
printf("%i \n", bytes[k]);
}
}