Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90395815
files.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 1, 07:23
Size
1007 B
Mime Type
text/x-c
Expires
Sun, Nov 3, 07:23 (2 d)
Engine
blob
Format
Raw Data
Handle
22028322
Attached To
rLAMMPS lammps
files.cpp
View Options
#include "stdio.h"
#include "string.h"
#include "files.h"
#define MAXLINE 256
/* ---------------------------------------------------------------------- */
void replace(char *file, char *header, int n, char **lines)
{
FILE *fpr = fopen(file,"r");
FILE *fpw = fopen("tmp.file","w");
char line[MAXLINE];
while (fgets(line,MAXLINE,fpr)) {
if (strstr(line,header)) {
fprintf(fpw,"%s",line);
for (int i = 0; i < n; i++) {
fgets(line,MAXLINE,fpr);
fprintf(fpw,"%s",lines[i]);
}
} else fprintf(fpw,"%s",line);
}
fclose(fpr);
fclose(fpw);
rename("tmp.file",file);
}
/* ---------------------------------------------------------------------- */
char **extract(char *file, char *header, int n, char **lines)
{
FILE *fp = fopen(file,"r");
char line[MAXLINE];
while (fgets(line,MAXLINE,fp)) {
if (strstr(line,header)) {
for (int i = 0; i < n; i++) {
fgets(line,MAXLINE,fp);
sprintf(lines[i],"%s",line);
}
break;
}
}
fclose(fp);
}
Event Timeline
Log In to Comment