change value for 2d array from input file and write the changed value into output file

Hello!

I'm a new with this programming. Currently, I am working with 2D array from input file, and need to change the value from it to new value and write into output file. Suppose, the 2d array is 10 x 10;

-99 -99 -99 -99 -99 -99 -99 -99 -99 -99
-99 -99 -99 7 8 9 -99 -99 -99 -99
7 6 8 6 5 -99 -99 -99 -99 -99
-99 -99 -99 -99 -99 6 7 8 5 4
1 2 3 4 5 6 7 8 -99 9
8 8 8 8 8 8 8 -99 -99 8
5 5 5 5 5 -99 -99 4 4 -99
-99 8 -99 -99 -99 -99 -99 -99 -99 -99
-99 -99 -99 -99 -99 -99 -99 -99 -99 -99
-99 -99 -99 -99 -99 -99 -99 -99 -99 -99

I would like to remain the int -99, and change value other than int -99 to int 2.

Below are the code am working with, and the new value changed into output file were not as what I want to, however. I would like to know where should I correct my code?

[code]

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ROWS 10
#define COLS 10

void main(void);

void main(void)
{
double link_file[ROWS][COLS] = { { 0 } };
char buffer[10];
double x = -99;
double y = 2;
FILE *infile;
FILE *outfile;
char tempchar;

//open file to read and to write
infile = fopen("C:\\test.txt", "rb");
outfile = fopen("C:\\test2.txt", "wb");


if (!x)
{
double y = 2;
int i = 0;
int j = 0;
for (infile, i = 1; i <= COLS; i++)
{
for (int j = 1; j <= ROWS; j++)
link_file[i][j] = 2;
}
}

else
{
double x = -99;
int i = 0;
int j = 0;
for (infile, i = 1; i <= COLS; i++)
{
for (int j = 1; j <= ROWS; j++)
link_file[i][j] = x;


}

fputs(buffer, outfile); // to save the changes made into output file

}

fclose(infile);
fclose(outfile);

printf("\n File restructured successfully !");

scanf("%s", &tempchar, 1); //hold the screen
}

Thank you in advance for your kind help!
Topic archived. No new replies allowed.