我正在创建一个用于将数字从文件读入数组的函数。但是从函数返回后,似乎丢失了最后一个值。这是我的代码:
void loadDataset(int* dataSet, int DataSetSize, char *filename) {
FILE *fp;
fp = fopen( filename , "r" );
for(int i=0; i< DataSetSize; i++){
fscanf(fp, "%d", &dataSet[sizeof(int) * i]);
}
for (int i = 0; i < DataSetSize; i++) {
printf("%d\n", dataSet[sizeof(int) * i]);
}
fclose(fp);
}
int main(int argc, char *argv[]) {
...
int* ds = malloc(sizeof(int) * DataSetSize);
loadDataset(ds, DataSetSize, DatasetFilename);
for (int i = 0; i < DataSetSize; i++) {
printf("%d\n", ds[sizeof(int) * i]);
}
...
}
Run Code Online (Sandbox Code Playgroud)
我正在测试的文件包含从1到6的数字。在运行时 …
我有一个看起来像这样的代码:
firstList = await GetFirstListFilesAsync();
textBlock1.Text = "found " + firstList.Count + " first list's results";
secondList = await GetSecondListFilesAsync();
textBlock2.Text = "found " + secondList.Count + " second list's results";
thirdList = await GetThirdListFilesAsync();
textBlock3.Text = "found " + thirdList.Count + " third list's results"
Run Code Online (Sandbox Code Playgroud)
所以现在它获得第一个列表,设置第一个TextBlock文本,然后获取第二个列表,设置第二个TextBlock文本,然后获取第三个列表并设置第三个TextBlock文本.但我希望所有等待操作同时运行,所以所有TextBlocks都会同时更新或更少.或者可能不是在同一时间 - 每个TextBlock都会在相应的await方法完成时更新.无论如何,我想在这里实现的目标是更快地获得结果.如果我一个接一个地运行这些方法,它们会等到上一个完成,但是如果它们同时运行,第三个方法会更快地返回结果,对吧?所以我的问题是 - 这可能吗?如果是,那怎么样?