Click here to Skip to main content
15,891,909 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<io.h>


void main()
{
    FILE *in;
    in = fopen("A.txt","r");
    double f;
    int i,j;
    n = 430;
    
    double **arr;
    arr = (double**)malloc(sizeof(double*)*430);
    for(i=0;i< 430; i++)
        arr[i] = (double*)malloc(sizeof(double)*430);

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {   
            fscanf(in, "%lf",&f);
            fprintf(stdout, "%.15lf",f);

            arr[i][j] = f;
            printf("A[%d][%d] = : %f",i,j,f);
        }
        getch();
    }

    cout<<endl<<" Matrix A Fed ";
    getch();

    fclose(in);
}


What I have tried:

Input is a matrix containing 430x430 double type values.
Output iterates till i=17 and stops.
Why so?
please help.
this arises from a bigger problem presented here.
c++ - LU decomposition using dynamic memory allocation for large Matrices. - Stack Overflow[^]
Posted
Updated 6-Apr-16 9:52am
v4
Comments
Member 12440837 6-Apr-16 11:47am    
the #include didnt show up.. no idea why
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<io.h>
Richard MacCutchan 6-Apr-16 11:53am    
Because you forgot to surround your code with <pre> tags. I think Jochen may be doing it as I write this.
Jochen Arndt 6-Apr-16 11:55am    
That is because the angle brackets are treated as HTML tags.
I fixed it for you.
Member 12440837 6-Apr-16 11:58am    
thanks for that
can u also fix the error?
Jochen Arndt 6-Apr-16 12:04pm    
You mean declaring double g and using f (I just recognised that)?
I will do so.

Two tips:
You can edit your question yourself using the green 'Improve question' link (move the mouse to the bottom right of your question to let the link show up).

To reply to a comment use the Reply button right of the poster's name. Than he will receive an email notification (like you will get now).

1 solution

Your program actually works. For sure it is not robust and you are probably feeding it with a bad data file.
A slightly modified it (removed the useless cout call, as well the legacy conio header, etc...)

C
 #include <stdio.h>
 #include <stdlib.h>

int main()
{
    FILE *in;
    in = fopen("A.txt","r");
    double f;
    int i,j;
    const int n = 430;

    double **arr;
    arr = (double**)malloc(sizeof(double*)*430);
    for(i=0;i< 430; i++)
        arr[i] = (double*)malloc(sizeof(double)*430);

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            fscanf(in, "%lf",&f);
            fprintf(stdout, "%.15lf",f);

            arr[i][j] = f;
            printf("A[%d][%d] = : %f",i,j,f);
        }
    }

    printf(" MAtrix A Fed \n");

    getchar();

    fclose(in);
}


then I fed it with the random numbers generated by the following program

 #include <stdio.h>
 #include <stdlib.h>
const int N = 430;

int main()
{
  int i,j;
  for (i=0; i<N; ++i)
    for(j=0; j<N; ++j)
    {
      if (j %10)
        printf(" ");
      else
        printf("\n ");

      float f = ((float)rand()/RAND_MAX);
      printf("%12g ", f);

    }
  return 0;
}



and eventually got the Matrix A Fed message.
 
Share this answer
 
Comments
[no name] 6-Apr-16 17:26pm    
A 5 for looking into the details.
CPallini 7-Apr-16 2:45am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900