Home > Back-end >  The numerical procedure with extracted from TXT units, the text is larger
The numerical procedure with extracted from TXT units, the text is larger

Time:10-11

Recently began to learn "computer network", the teacher to the question: use the PING command or Tracert command to obtain network latency, choose five typical sites, the observation time interval for 30 seconds, at least 12 hours, map network latency, strives for the mean and variance, recently have no idea, comment, thank you, teacher said that can be written in C language or assembler a delay,,,,,,,, have the test data, is can't extract, strives for the program

CodePudding user response:

Fopen
The fgets
Sscanf
fclose

CodePudding user response:

Fyi:
 # include & lt; stdio.h> 
#include
# define MAXLEN 1000
The FILE * f;
Char ln [MAXLEN];
Char fn [256].
Int L;
int n;
Int v1.
Int v2;
Void main () {
Strcpy (fn, "in the. TXT");
F=fopen (fn, "r");
If (NULL==f) {
Fprintf (stderr, "Can not open the file [% s]! \ n ", fn);
return;
}
n=0;
While (1) {
If (NULL==the fgets (ln, MAXLEN, f)) break;
n++;

If (NULL==STRSTR (ln, "object")) printf (" % s ", ln);

L=strlen (ln).
If (=='\ n' ln [L - 1]) {
Ln] [L - 1=0;
} else {
Fprintf (stderr, "long (& gt;=% d) at the line % d: % s... MAXLEN \ n ", n, ln);
break;
}

If (==2 sscanf (ln, "% d % * s % d", & amp; V1, & amp; V2)) {
If (1 & lt;=v1 & amp; & V1 & lt;=10
& & 1<=v2 & amp; & V2 & lt;=10) {
Printf (" % d, % d \ n ", v1, v2);
} else {
Fprintf (stderr, "Data (% d, % d) Invalid at line % d: % s \ n", v1, v2, n, ln);
}
} else {
Fprintf (stderr, "Format error at line % d: % s \ n", n, ln);
}
}
The fclose (f);
}

CodePudding user response:

Text form such as:
Is Ping xdwscache.glb0.lxdns.com 163. [162.105.28.233] with 32 bytes of data:
Reply from 162.105.28.233: bytes=32 time=4 ms TTL=54

162.105.28.233 Ping statistical information:
Packets: already sent=1, has been receiving=1, lost=0 loss (0%),
Round trip of the estimated time (in milliseconds) :
The shortest=4 ms, the longest=4 ms, average=4 ms

Is Ping xdwscache.glb0.lxdns.com 163. [162.105.28.233] with 32 bytes of data:
A reply from 162.105.28.233: bytes=32 time=18 ms TTL=54

162.105.28.233 Ping statistical information:
Packets: already sent=1, has been receiving=1, lost=0 loss (0%),
Round trip of the estimated time (in milliseconds) :
=18 ms shortest, the longest=18 ms, average=18 ms,
I want the inside of the extraction time="ms" the figures, but also wrote another in the text, is that ok?
  • Related