This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
#include <stdio.h>
#include <stdlib.h>
#define DOUBLESIZE sizeof(double)
void multiply(FILE *fin, FILE *fout, double scalar, long total)
{
double number;
fread(&number, DOUBLESIZE, 1, fin);
while (!feof(fin)) {
number *= scalar;
fwrite(&number, DOUBLESIZE, 1, fout);
total--;
if (total == 0)
return;
fread(&number, DOUBLESIZE, 1, fin);
}
}
int main(int argc, char *argv[])
{
FILE *fileIn;
FILE *fileOut;
double scalar;
char *endptr;
long skip, total;
switch (argc) {
case 6:
fileIn = fopen(argv[2], "r+");
if (!fileIn) {
fprintf(stderr, "Unable to open %s\n", argv[2]);
exit(2);
}
fileOut = fopen(argv[3], "w+");
if (!fileOut) {
fprintf(stderr, "Unable to open %s\n", argv[3]);
exit(2);
}
break;
default:
fprintf(stderr, "Usage: %s scalar source destination skip size\n", argv[0]);
exit(1);
}
scalar = strtod(argv[1], &endptr);
if (*endptr) {
fprintf(stderr, "%s is not a valid floating point number\n", argv[1]);
exit(3);
}
skip = strtol(argv[4], &endptr, 0);
if (*endptr) {
fprintf(stderr, "%s is not a valid integer number\n", argv[1]);
exit(3);
}
total = strtol(argv[5], &endptr, 0);
if (*endptr) {
fprintf(stderr, "%s is not a valid integer number\n", argv[1]);
exit(3);
}
if (fseek(fileIn, skip, SEEK_SET) != 0) {
fprintf(stderr, "fseek failed\n");
exit(3);
}
if (fseek(fileOut, skip, SEEK_SET) != 0) {
fprintf(stderr, "fseek failed\n");
exit(3);
}
total /= DOUBLESIZE;
multiply(fileIn, fileOut, scalar, total);
fclose(fileIn);
fclose(fileOut);
return 0;
}
Attachment:
script.sh
Description: application/shellscript
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |