在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; int index; int* readFile(char* filename) { int* array; FILE* fp = fopen(filename, "r"); if (!fp) { cout << "hello" << endl; return 0; } char* pBuf; int fLen; fseek(fp, 0, SEEK_END); fLen = ftell(fp); rewind(fp); array = (int*)malloc(fLen*4); pBuf = (char*)malloc(fLen + 1); index = 1; for (int i = 0; i < fLen; i++) { fscanf(fp, "%d", array + i); if (ftell(fp) == fLen) { break; } index++; } fclose(fp); array = (int *)realloc(array, index*4); cout << "indexΪ" << index << endl; return array; } int main() { char wFilename[] = "weight.txt"; char vFilename[] = "values.txt"; int* weights = readFile(wFilename); int* values = readFile(vFilename); for (int t = 0; t < index; t++) cout << weights[t] << endl; cout << "_______________________________" << endl; for (int t = 0; t < index; t++) cout << values[t] << endl; free(weights); free(values); }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论