I'm having some trouble with using fscanf in C. I've written a random matrix to a file and am now trying to read the data in the text file into another matrix. It seems to read the number of rows and columns fine, but it returns zeros for the data values. I'm completely stuck, so any help would be appreciated!
My MATRIX stucture is declared as
typedef struct matrep {
unsigned rows, columns;
double *data;
}MATRIX;
My file looks like this:
rows = 5, columns = 10
-99.75 12.72 -61.34 61.75 17.00 -4.03 -29.94 79.19 64.57 49.32
-65.18 71.79 42.10 2.71 -39.20 -97.00 -81.72 -27.11 -70.54 -66.82
97.71 -10.86 -76.18 -99.07 -98.22 -24.42 6.33 14.24 20.35 21.43
-66.75 32.61 -9.84 -29.58 -88.59 21.54 56.66 60.52 3.98 -39.61
75.19 45.34 91.18 85.14 7.87 -71.53 -7.58 -52.93 72.45 -58.08
And this is my matrix_read function:
MATRIX matrix_read(char file_name[15])
{
int i,j, m, n;
MATRIX B;
FILE *filep;
double *ptr = NULL;
double x;
if((filep = fopen("matrixA.txt", "r"))==NULL)
{
printf("\nFailed to open File.\n");
}
if(fscanf(filep, "\n\nrows = %u, columns = %u\n\n", &m, &n) != 2)
{
printf( "Failed to read dimensions\n");
B.data = 0;
B.columns = 0;
B.rows = 0;
}
B.data = (double *)malloc(B.columns*B.rows*sizeof(double));
if(B.data ==0)
{
printf("Failed to allocate memory");
}
fscanf(filep,"\n\nrows = %u, columns = %u\n\n",&m,&n);
rewind(filep);
ptr = B.data;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
if (fscanf(filep, " %5.2lf", &x) != 1)
{
printf("Failed to read element [ %d,%d ]\n", i, j);
B.data = 0;
B.columns = 0;
B.rows = 0;
}
printf("%5.2lf\t", x);
*ptr++ = x;
}
}
B.rows=m;
B.columns=n;
return B;
fclose(filep);
free(ptr);
}
Thanks!
You have several problems, one of them is pointed by #simonc, another possible one:
you rewind after reading columns and rows in filep
rewind() sets the position indicator associated with stream to the beginning of the file, you are reading again rows = 5, columns = 10
Finally:
B.data = (double *)malloc(B.columns*B.rows*sizeof(double)); /* Don't cast malloc */
if(B.data ==0)
{
printf("Failed to allocate memory");
/* You have to return or exit here */
}
As Alter Mann denoted, drop the second
fscanf(filep,"\n\nrows = %u, columns = %u\n\n",&m,&n);
as well as the
rewind(filep);
moreover, " %5.2lf" is not a valid scanf conversion specification (you could read the manual about this) - use "%lf" instead.
Related
I am trying to read a text file with 100 numbers like 1 2 45 55 100 text file here (all on a single line) and then put them in a 10x10 array (2D array).
736.2 731.6 829.8 875.8 568.3 292.2 231.1 868.9 66.7 811.9 292.0 967.6 419.3 578.1 322.5 471.7 980.0 378.8 784.1 116.8 900.4 355.3 645.7 603.6 409.1 652.1 144.1 590.6 953.1 954.0 502.0 689.3 685.6 331.9 565.1 253.9 624.1 796.2 122.8 690.7 608.0 414.8 658.3 27.3 992.9 980.8 499.0 972.8 359.7 283.1 89.7 260.1 638.4 735.4 863.6 47.5 387.5 7.7 638.1 340.6 961.7 140.1 29.8 647.3 471.9 594.9 901.2 96.0 391.1 24.0 786.7 999.1 438.7 445.0 26.4 431.6 425.9 525.4 404.4 785.6 808.5 494.1 45.7 447.0 229.5 909.3 494.4 617.0 917.0 132.5 957.5 878.8 272.6 987.4 526.1 744.5 582.3 427.3 840.5 973.3
Here is my code:
#include <stdio.h>
#define NR 10
#define NC 10
int main(void) {
int numbers[9][9];
int i = 0;
int count;
int j = 0;
FILE *file;
file = fopen("numbers.txt", "r");
for (count = 1; count < 101; count++) {
fscanf(file, "%d", &numbers[i][j]);
j++;
if ((count != 1) && (count % 10 == 0)) {
i++;
j = 0;
}
}
fclose(file);
int p = 0;
int q = 0;
for (p = 0; p < NR; p++) {
for (q = 0; q < NC; q++) {
printf("%d", numbers[p][q]);
}
printf("\n");
}
return 0;
}
As SparKot noted in a comment, to read a 10x10 matrix, you need to define the matrix with 10x10 elements:
int numbers[10][10];
That has to be one of the weirder ways of reading a 10x10 matrix that I've ever seen. Why not go for a simple approach of nested loops. Since the data contains floating-point numbers, you need to read them as double (or perhaps float) values.
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
double double_val;
if (fscanf(file, "%lf", &double_val) != 1)
{
fprintf(stderr, "failed to read matrix[i][j]\n", i, j);
exit(EXIT_FAILURE);
}
numbers[i][j] = double_val;
}
}
The mess with double_val works around the data containing floating point numbers and your original code trying to read integers. You'll get one valid value; thereafter, fscanf() will return 0 because the . is not a part of a valid integer. This highlights the importance of checking the return value from fscanf() and its relatives.
Frankly, you should be using double numbers[10][10]; for the data from the file. Then you could read directly into the array:
if (fscanf("%lf", &numbers[i][j]) != 1)
But you'd need to check (and probably change) all the rest of the code too.
There are multiple issues in your code:
the matrix is too small, make it numbers[NR][NC].
you do not check for fopen failure: you will have undefined behavior if the file numbers.txt is not in the current directory or cannot be open for reading.
you read the file contents as integers, but the file contains floating point numbers with a . decimal separator: the second and subsequent fscanf() will get stuck on the . and keep returning 0 without modifying the destination number, leaving the matrix mostly uninitialized. Make the matrix double numbers[NR][NC], read the numbers with %lf and test for conversion failure.
the counting method in the reading loop is weird. Just use 2 nested for loops with proper counter and tests.
printing the matrix contents, you should output at least a space between numbers so the output is readable.
Here is a modified version:
#include <errno.h>
#include <stdio.h>
#include <string.h>
#define NR 10
#define NC 10
int main() {
double numbers[NR][NC];
FILE *file;
file = fopen("numbers.txt", "r");
if (file == NULL) {
fprintf(stderr, "cannot open numbers.txt: %s\n", strerror(errno));
return 1;
}
for (int i = 0; i < NR; i++) {
for (int j = 0; j < NC; j++) {
if (fscanf(file, "%lf", &numbers[i][j]) != 1) {
fprintf(stderr, "error reading number at row %d, col %d\n",
i + 1, j + 1);
fclose(file);
return 1;
}
}
}
fclose(file);
for (int p = 0; p < NR; p++) {
for (int q = 0; q < NC; q++) {
printf(" %5g", numbers[p][q]);
}
printf("\n");
}
return 0;
}
Clear all a common condition that causes programs to crash; they are often associated with a file named core.
code is showing segmentation fault.
The following program attempts to read an input file line by line using fgets, and save each comma delimited float value into an array of structs using sscanf (this aspect of the code works fine). The issue lies in that the program should also detect when a float value is missing/empty, and assign it the float value 1.500 which then is saved into the array of structs.
EDIT: This is supposed to be compiled using VS2017, so on Windows.
*Note: Please note that the following questions have been studied before posting this question:
How to check if a string returned by scanf is null
How to get scanf to continue with empty scanset
An example of the input file (missing value in the second row):
0.123f, 0.234f, 0.345f, 0.456f, 0.567f
1.987f, , 7.376f, 2.356f, 5.122f
9.111f, 1.234f, 7.091f, 6.672f, 9.887f
Desired output (missing value in second row is detected and set to 1.500):
0.123 0.234 0.345 0.456 0.567
1.987 1.500 7.376 2.356 5.122
9.111 1.234 7.091 6.672 9.887
So far, the first attempt tried to scan all 5 floats (each with 'f' suffix) into strings and then check to see if those strings are null/empty or of zero length using strcmp and strlen, respectively, and finally involved trying to use sscanf again on each of those variables to read each into an array of structs.
The 2nd attempt included a check to see if the sscanf was successful by using if (sscanf(line, "%ff", &data[i].x) == NULL) { // ...some alert and assign 1.500}, which did not work either. The 3rd attempt, as seen below:
#include "stdio.h"
int main() {
typedef struct {
float x, y, vx, vy, mass;
}DATA;
FILE *file = fopen("null_detector.txt", "r");
if (file == NULL)
{
printf(stderr, "ERROR: file not opened.\n");
return EXIT_FAILURE;
}
int N= 3;
DATA* data = malloc(Nbodies * sizeof * data); // Array allocation
char line[256];
int i;
int inc = 1;
for (i = 0; i < Nbodies; i += inc)
{
fgets(line, sizeof(line), file);
// **Some info:
// Scan 5 float variables per line (this part works fine)
sscanf(line, "%ff, %ff, %ff, %ff, %ff",
&data[i].x, &data[i].y, &data[i].vx, &data[i].vy, &data[i].mass); // %ff accounts for 'f' suffix
// Now check if any of above vars are empty/NULL.
// NOTE: aware that these vars CANNOT be compared to NULL,
// but has been included to try and provide clarity for end goal
if (data[i].x == NULL)
{
//.. assign 1.500 to data[i].x
}
if (data[i].y == NULL)
{
//... same as above etc
}
// ...Repeat IF statements for all 5 vars
}
//Print the contents of array of structs to check for correct output
for (i = 0; i < Nbodies; i++)
{
printf("%.3f %.3f %.3f %.3f %.3f\n", data[i].x, data[i].y, data[i].vx, data[i].vy, data[i].mass);
}
return 0;
}
Summary:
Does anyone know how this program can be modified to:
detect missing float values in each line of the file upon reading them with fgets
replace missing float values with the float value 1.500
write these values to the array of structs, like the non-missing values successfully are doing?
As commented in the code, I am aware that the struct float variables cannot be compared to NULL. I have included this comparison in the code to only try to add some clarity as to what the end goal is.
You can use strsep to separate each line.
str = strsep(&line, ",")
Using one function to set the value of data:
void set_data(DATA *dt, int count, float f) {
switch(count) {
case 0: dt->x = f; break;
case 1: dt->y = f; break;
case 2: dt->vx = f; break;
case 3: dt->vy = f; break;
case 4: dt->mass = f; break;
}
}
The complete code:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
float x, y, vx, vy, mass;
}DATA;
void set_data(DATA *dt, int count, float f) {
switch(count) {
case 0: dt->x = f; break;
case 1: dt->y = f; break;
case 2: dt->vx = f; break;
case 3: dt->vy = f; break;
case 4: dt->mass = f; break;
}
}
int main() {
FILE *file = fopen("text.txt", "r");
if (file == NULL)
{
printf( "ERROR: file not opened.\n");
return EXIT_FAILURE;
}
int N= 3;
DATA* data = malloc(N * sizeof(data)); // Array allocation
char *line;
int i;
int inc = 1;
size_t n = 0;
for (i = 0; i < N; i += inc)
{
getline(&line, &n, file);
int count = 0;
char *str;
while((str = strsep(&line, ",")) != NULL) {
if (strcmp(str, " ") == 0) {
set_data(&data[i], count, 1.5);
} else {
set_data(&data[i], count, atof(str));
}
// printf("count = %d\n", count);
// printf("token: %s\n", str);
count++;
}
}
//Print the contents of array of structs to check for correct output
for (i = 0; i < N; i++)
{
printf("%.3f %.3f %.3f %.3f %.3f\n", data[i].x, data[i].y, data[i].vx, data[i].vy, data[i].mass);
}
return 0;
}
The input:
#cat text.txt
0.123f, 0.234f, 0.345f, 0.456f, 0.567f
1.987f, , 7.376f, 2.356f, 5.122f
9.111f, 1.234f, 7.091f, 6.672f, 9.887
The output:
0.123 0.234 0.345 0.456 0.567
1.987 1.500 7.376 2.356 5.122
9.111 1.234 7.091 6.672 9.887
It can also achieved with only sscanf if there is at least a space between the commas when there is an absence of an input value.
#include <stdio.h>
int main(void) {
char *str[] = {"0.123f, 0.234f, 0.345f, 0.456f, 0.567f",
"1.987f, , 7.376f, 2.356f, 5.122f",
"9.111f, 1.234f, 7.091f, 6.672f, 9.887f"};
float float_arr[3][5];
char temp[5][7];
for (unsigned i = 0; i < 3; i++) {
if (5 != sscanf(str[i], "%6[^,],%6[^,],%6[^,],%6[^,],%6[^,]",
temp[0], temp[1], temp[2], temp[3], temp[4]))
return printf("Error\n"), 1;
for (unsigned j = 0; j < 5; j++)
if (1 != sscanf(temp[j], "%ff", &float_arr[i][j]))
float_arr[i][j] = 1.500f;
}
// printing the result
for (unsigned i = 0; i < 3; i++) {
for (unsigned j = 0; j < 5; j++)
printf("%ff ", float_arr[i][j]);
printf("\n");
}
return 0;
}
Output
0.123000f 0.234000f 0.345000f 0.456000f 0.567000f
1.987000f 1.500000f 7.376000f 2.356000f 5.122000f
9.111000f 1.234000f 7.091000f 6.672000f 9.887000f
I have 8 files (file%d-%d.dat) each with 2 columns and 1000 rows:
File1-1 File1-2 File1-3 File1-4
x1a y1a x1b y1b x1c y1c x1d y1d
x2a y2a x2b y2b x2c y2c x2d y2d
x3a y3a x3b y3b x3c y3c x3d y3d
. . . .
. . . .
File2-1 File2-2 File2-3 File2-4
x1e y1e x1f y1f x1g y1g x1h y1h
x2e y2e x2f y2f x2g y2g x2h y2h
x3e y3e x3f y3f x3g y3g x3h y3h
. . . .
. . . .
I want to sum the second column of each file File%d-1 row by row and write the sum in a new file: Filesum1; same for File%d-2 and so on, i.e.,
Filesum1 Filesum2 and so on ..
x1a+x1e y1a+y1e x1b+x1f y1b+y1f .
x2a+x3e y2a+y2e x2b+x2f y2b+y2f .
. . . .
. . . . .
I created 4 new files:
#include <stdio.h>
int main(void)
{
int numfiles=4;
int numfileread=8;
int i,yy1, yy2, x0, x1;
FILE *files[numfiles];
FILE *f[numfileread];
for (int n = 0; n < 4; n++)
{
char filename[4];
sprintf(filename, "filesum%d.dat", n);
files[n] = fopen(filename, "w");
}
Then I've tried this, but it does not work correctly:
for (int n = 0; n < 4; n++)
{
yy1=0;
yy2=0;
for(int r=1;r<4;r++)
{
char file[8];
sprintf(file, "file%d-%d.dat", r, n);
f[i] = fopen(file, "r");
fscanf(f," %d %d",&x0,&x1);
yy1+=x0;
yy2+=x1;
fclose(f);
i++;
}
fprintf(files,"%d %d\n",yy1, yy2);
fclose(files);
}
If I had the same assignment, but for reading 50 files:
readFile1, readFile2, readFile3, ......., readFile50
How can I change the code?
There are multiple issue:
This loop will only three times, I think you intended it to run 4 times.
for(int r=1;r<4;r++)
Char array file does not has sufficient space to hold string "file%d-%d.dat"
fclose(f); needs to be changed to fclose(f[i]);
You need to specify an index for files.
fprintf(files,"%d %d\n",yy1, yy2);
This is what I came up with. You can try it out.
#include <stdio.h>
int main(){
FILE *readFile1;
FILE *readFile2;
FILE *writeFile;
char inFile1[32] = {0};
char inFile2[32] = {0};
char sumFile[32] = {0};
int i,xa,xb,ya,yb;
int ret1;ret2;
for(i=0;i<4;i++){
sprintf(inFile1, "File1-%d", i);
sprintf(inFile2, "File2-%d", i);
sprintf(sumFile, "sumFile%d", i);
readFile1 = fopen(inFile1, "r");
readFile2 = fopen(inFile2, "r");
writeFile = fopen(sumFile, "w");
while(1){
ret1 = fscanf(readFile1, "%d %d", &xa, &ya);
ret2 = fscanf(readFile2, "%d %d", &xb, &yb);
if( (ret1 != 2) || (ret2 != 2) )
break;
fprintf(writeFile, "%d %d", xa+xb, ya+yb);
}
fclose(readFile1);
fclose(readFile2);
fclose(writeFile);
}
return 1;
}
Okay, so you have a large number of files and want to sum two columns of data over these files. You also know that you will have 1000 rows of data in each file. You could try to keep all files open with an array of file handles and read from them in turn, but that's too complicated. Instead:
define an array for each column and initialise it to zero;
open one file at a time, read the data, add it to the array and close that file;
write the summed data to the results file.
There will always be at most one open file with this solution.
The code would look like this:
#include <stdlib.h>
#include <stdio.h>
enum {
nData = 1000, // number of rows
nFiles = 50, // number of files per block
nBlocks = 4 // number of blocks
// nomenclature: file{file}-{block}.dat
};
int main(void)
{
for (int j = 0; j < nBlocks; j++) {
double col1[nData] = {0.0};
double col2[nData] = {0.0};
char outn[32];
FILE *out;
for (int i = 0; i < nFiles; i++) {
char fn[32];
FILE *f;
snprintf(fn, sizeof(fn), "file%d-%d.dat", i, j);
f = fopen(fn, "r");
if (f == NULL) {
fprintf(stderr, "Could not open '%s'.\n", fn);
exit(1);
}
for (int k = 0; k < nData; k++) {
char line[80];
double x, y;
if (fgets(line, sizeof(line), stdin) == NULL) break;
if (sscanf(line, "%lf %lf", &x, &y) != 2) continue;
col1[k] += x;
col2[k] += y;
}
fclose(f);
}
snprintf(outn, sizeof(outn), "filesum-%d.dat", j);
out = fopen(outn, "r");
if (out == NULL) {
fprintf(stderr, "Could not write to '%s'.\n", outn);
exit(1);
}
for (int k = 0; k < nData; k++) {
fprintf(out, " %15g %15g\n", col1[k], col2[k]);
}
fclose(out);
}
return 0;
}
Season to taste.
I have an issue with input in my homework. On stdin, I will get a specifically formatted input.
In first line, there will be 2 integers, that determine the size of a matrix (rows and cols). All the lines after represent rows of the matrix.
I essentially want to do something like getline(), but I don't want to use getline(). In fact I can't, its forbidden in the homework. Therefore I have to scan int by int (or char by char I guess). The issue here is I need it to be bulletproof (almost). Dummy-proof at least.
I'm imagining a big while loop that keeps going until EOF and inside that another loop (perhaps?) which always reads a line, saves it to my allocated matrix and carries on to the next. I'm aware that I'm supposed to be checking for '\n', but I kind of lack the ability to think of a solution today.
Here's what I'm working with: My matrices are a structure.
struct Matrix{
int nrows;
int ncols;
int** matrix;
};
I then have multiple functions.
A function to dynamically allocate space for the matrix of specific size:
struct Matrix init_matrix(int r, int c)
{
struct Matrix mat;
mat.nrows = r;
mat.ncols = c;
mat.matrix = calloc(r, sizeof(int *));
for(int i = 0; i < r; ++i)
{
*(mat.matrix+i) = calloc(c, sizeof(int));
}
return mat;
}
A function to free the previously allocated space:
void free_matrix(struct Matrix mat)
{
int top = mat.nrows;
for(int i = 0; i < top; ++i)
{
free(mat.matrix[i]);
}
free(mat.matrix);
}
Those 2 functions work perfectly fine.
Now I'm trying to make a function create_matrix(void) (at least I think it shouldn't take any args), that will read the input I'm supposed to receive, for example:
3 3
1 2 3
4 5 6
7 8 9
when the function reads the input, it could tell if the input is incorrect or is in incorrect format and exit the program with corresponding exit value (like 100 f.e.) If the input is correct and in correct format, it calls init_matrix() and then saves input to the matrix.
For your deeper understanding: the whole input I'm supposed to receive is:
matrix A (like above, size in first line, values in lines after)
an operation (+,-,*)
matrix B
Then execute the operation (A*B, A+B etc.). I'm trying to make most things into functions, so the main would be very simple, f.e.
int main(int argc, char *argv[])
{
struct Matrix mat1 = create_matrix();
char operation = get_operation();
struct Matrix mat2 = create_matrix();
struct Matrix result = compute(mat1,mat2, operation);
return 0;
}
Something in those lines, if you get me. The thing is I want to make the program complex enough so that I could later edit it to handle a bigger sequence (up to 100) of matrices than just two. Right now I could do it the dirty way, make it work for two matrices with one operation, but that's not what I really want.
Well, here's how I solved it. It works. It's not anywhere close to perfect, but it works, upload system took it and gave it full amount of points, so I'm satisfied.
struct Matrix read_matrix(FILE *fp)
{
struct Matrix mat;
//FIRST LINE
int ch;
int i = 0;
int n = 20;
char* line = calloc(n,sizeof(char));
while((ch = fgetc(fp)) != EOF && ch != '\n')
{
*(line + i++) = ch;
}
*(line + n-1) = '\0';
int r,c;
int k = sscanf(line,"%d %d", &r, &c);
if(k != 2)
{
fprintf(stderr, "Error: Chybny vstup!\n");
exit(100);
}
free(line);
//MATRIX
line = calloc(c, sizeof(int));
mat = init_matrix(r, c);
i = 0;
r = 0;
while(r < mat.nrows && (ch = fgetc(fp)))
{
if(ch == '\n' || ch == EOF)
{
*(line + i) = '\0';
int offset;
char *data = line;
for(int j = 0; j < mat.ncols; ++j)
{
int d = sscanf(data, " %d%n", &mat.matrix[r][j], &offset);
if(d != 1){
fprintf(stderr, "Error: Chybny vstup!\n");
exit(100);
}
data += offset;
}
i = 0;
++r;
if(ch == EOF){
break;
}
} else
{
*(line + i++) = ch;
}
}
free(line);
return mat;
}
I am new to C and have been trying to do this for a while now.
I need to read the integer values from a text file that has :
G = 10
P = 5
Gayle: 1,2,3,4
Price: 4,3,5,6.6
Need to pick out the Gayle and Price values and store them in 2 seperate arrays and store the G and P values in 2 separate variables.
So far I have done :
FILE* file = fopen(abc.txt, "r");
//for gayle values
int g_array[100];
int i=0;
int gayle_val;
while(fscanf("%d", &gayle_val)==1)
{
g_array[i]=gayle_val;
}
//for price values
int p_array[100];
int i=0;
int price_val;
while(fscanf("%d", &price_val)==1)
{
p_array[i]=price_val;
}
//for G and P values
How do I combine the searches for the 4 lines such that the read is done line by line and values stored accordingly ?
Thank you so much in advance !
This has been answered before and I'm pretty sure it was suggested to you as the question was typed:
I am not going to give you a code sample but instead am going to advise you on what could be done to get the contents of the file to be inserted in a single array rather than one.
Try to create a 2D array instead and assigning the values to it rather than having multiple arrays and use a FOR loop to do so.
simple E.G.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
int gayle_val, g_array[100], g_count, p_count;
float price_val, p_array[100];
int i;
char line_buff[128], *p;
FILE *file = fopen("abc.txt", "r");
while(NULL!=fgets(line_buff, sizeof(line_buff), file)){
if(strncmp("G = ", line_buff, 4) == 0){//simple match
gayle_val = atoi(line_buff + 4);
} else if(strncmp("P = ", line_buff, 4) == 0){
price_val = atof(line_buff + 4);
} else if(strncmp("Gayle: ", line_buff, 7) == 0){
g_count = 0;
for(p = line_buff + 7;NULL!=(p=strtok(p, ","));p=NULL){
g_array[g_count++] = atoi(p);
}
} else if(strncmp("Price: ", line_buff, 7) == 0){
p_count = 0;
for(p = line_buff + 7;NULL!=(p=strtok(p, ","));p=NULL){
p_array[p_count++] = atof(p);
}
}
}
fclose(file);
//check print
printf("gayle_val: %d\n", gayle_val);
printf("gayle: ");
for(i = 0;i<g_count;++i)
printf("%d ", g_array[i]);
printf("\n");
printf("price_val: %g\n", price_val);
printf("price: ");
for(i = 0;i<p_count;++i)
printf("%g ", p_array[i]);
printf("\n");
return 0;
}