AAA BBB 1111
AAA CCC 22222
BBB CCC 333333
for (int i = 0; i < k; i++)
{
fgets(str, 32, FILE_IN);
sscanf(str, "%s %s %d\n", src, dst, &cost);
}
fscanf(FILE_IN, "%s %s %d\n", src, dst, &cost);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
int main(int argc, char** argv)
{
int fin = open(argv[1], O_RDONLY);
struct stat finfo = {0};
fstat(fin, &finfo);
char *map = mmap(0, finfo.st_size, PROT_READ, MAP_SHARED, fin, 0);
char src[4] = {0};
char dst[4] = {0};
int cost;
int i;
int off = 0;
while (off < finfo.st_size)
{
memcpy(src, map + off, 3);
memcpy(dst, map + off + 4, 3);
i = 0;
cost = 0;
while (map[off + 8 + i] != 10) {
cost = cost * 10 + map[off + 8 + i] - 48;
++i;
};
off += 9 + i;
};
munmap(map, finfo.st_size);
close(fin);
return EXIT_SUCCESS;
}