我是新来的,我的作业需要帮助。我有这个二进制文件阅读器功能,直到我在结构中更改了变量类型之前,它一直运行良好。所以变量是typedef struct planetype
{
char t[10 + 1];
struct planetype next;
}planeytype;
typedef struct planedata
{
char name[60 + 1];
char nation[4 + 1];
int speed;
int max_altitude;
int takeoff_run;
int weight;
int max_bomb_weight;
int max_ammo_count;
double caliber;
struct planetype* tp;
struct planedata* next;
} planedata;
void new_type(planedata *akt, char* value) //pipa
{
planetype* type = (planetype*)malloc(sizeof(planetype));
strcpy(type->t, value);
type->next = akt->tp;
akt->tp = type;
//printf("%s", value);
}
void bin_read(planedata*head)
{
int IsEnd = 0;
char ch = '\0';
char tempname[40 + 1];
FILE *f1;
int n;
int i;
char *k;
planedata* data = head->next;
f1 = fopen("type.dat", "rb");
while (!IsEnd)
{
n = 0;
while (ch != ' ' && IsEnd != 1)
{
fread(&ch, sizeof(char), 1, f1);
if (ch == '\n')
{
IsEnd = 1;
}
if (ch != '\n')
{
tempname[n] = ch;
printf("%c", ch);
n++;
}
}
if (IsEnd != 1)
{
tempname[n - 1] = '\0';
printf("%s ", tempname);
data = PlaneName(head, tempname);
for (i = 0; i < 1; i++)
{
fread(&k, sizeof(int), 1, f1);
printf("%s", k);
new_type(data, k);
}
}
fread(&ch, sizeof(char), 1, f1);
}
fclose(f1);
}
,现在它是new_type
结构中的char [n]字符串。
现在代码冻结了。
以下是代码:
strcpy
当调试器到达strings.txt
函数和@input =
EXTRACT filepath string
FROM "/input/strings.txt"
USING Extractors.Tsv();
// Give the strings a row-number
@input =
SELECT ROW_NUMBER() OVER() AS rn,
filepath
FROM @input;
// Get the cities
@cities =
EXTRACT city string
FROM "/input/cities.txt"
USING Extractors.Tsv();
// Ensure there is a lower-case version of city for matching / joining
@cities =
SELECT city,
city.ToLower() AS lowercase_city
FROM @cities;
// Explode the filepath into separate rows
@working =
SELECT rn,
new SQL.ARRAY<string>(filepath.Split('\\')) AS pathElement
FROM @input AS i;
// Explode the filepath string, also changing to lower case
@working =
SELECT rn,
x.pathElement.ToLower() AS pathElement
FROM @working AS i
CROSS APPLY
EXPLODE(pathElement) AS x(pathElement);
// Create the output query, joining on lower case city name, display, normal case name
@output =
SELECT c.city,
COUNT( * ) AS records
FROM @working AS w
INNER JOIN
@cities AS c
ON w.pathElement == c.lowercase_city
GROUP BY c.city;
// Output the result
OUTPUT @output TO "/output/output.txt"
USING Outputters.Tsv();
//OUTPUT @working TO "/output/output2.txt"
//USING Outputters.Tsv();
行时,程序就会死掉。