So I have a big text file with data in it and I would like to rearrange it. The data has a combination of integers and floats per each line but I'm only interested in grabbing the first integer, which is either a 1 or 0, and putting it at the end of the line.
For example, in my data file, I have the following line
1 0.41 1 44
and I would like to be
0.41 1 44 1
This is what I have so far and can't get it to work right. Thanks.
void main() {
FILE *fp;
FILE *out;
char str[15];
char temp;
fp = fopen("dust.txt", "r+");
out = fopen("dust.dat", "w");
while(fgets(str, sizeof(str), fp) != NULL) {
temp = str[0];
str[strlen(str)] = ' ';
str[strlen(str)+1] = temp;
str[strlen(str)+2] = '\r';
str[strlen(str)+3] = '\n';
fwrite(str, 1, strlen(str), out);
}
fclose(fp);
fclose(out);
}