我只想读取 IP 并在没有空格的情况下打印它们。这是我的代码的一部分:
char buffer[256]
dns_serv = fopen("dns_servers.conf", "rt"));
log = fopen("logfile", "at")) ;
if (!fgets(buffer,sizeof(buffer), dns_serv)) {
break;
}
if (buffer[0] == '#') continue;
if (buffer[0] == '\n') continue;
if ((sockdns = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
printf("Error\n");
continue;
}
fprintf(log, "; %s - %s %s",buffer,argv[1], argv[2]);
这在日志文件上写给我:
; 141.85.128.1
- google.com SOA
但我想把它写在同一行:
; 141.85.128.1 - google.com SOA
我的错误在哪里?这是 dns_servers.conf:
# first example
141.85.128.1
# another
# 61.34.189.250