Search
 
SCRIPT & CODE EXAMPLE
 

C

how to read 2d array from a file in c

/*
File structure:
3
150 250 150 20
180 -240 -150 150
200 0 0 200
*/

typedef struct{
    float r;
    float a;
    float b;
    float c;
} sphere; //sphere parameter

FILE *fp;

fp = fopen("C:UsersASUSDocumentsNumerical Methods labsphere projection
ead_values_of-sphere.txt", "r");


int n;
fscanf(fp, "%d
",&n);

printf("%d
",n);

sphere sp[n];

for(int i=0;i<n;i++){
	fscanf(fp, "%f %f %f %f
", &sp[i].r, &sp[i].a, &sp[i].b, &sp[i].c);
}

for(int i=0;i<n;i++){
  printf("%f ", sp[i].r);
  printf("%f ", sp[i].a);
  printf("%f ", sp[i].b);
  printf("%f
", sp[i].c);
}
Comment

PREVIOUS NEXT
Code Example
C :: do...while loop c 
C :: printf("%3d ",XX); 
C :: Palindrome number in c program 
C :: second largest element in an array 
C :: how to change background color in c programming 
C :: declare string in c 
C :: C - program to create 1D array 
C :: rfid rc522 code 
C :: hourglass sum 
C :: set all pins as output for loop 
C :: pasar a binario recursivo 
C :: delay in c programming for linux 
C :: definir função em c 
C :: c programming exercises 
C :: convert video to gif with ffmpeg 
C :: struct in struct 
C :: how to print logs when doing unit-testing in rust 
C :: unused variable in c 
C :: what is O(N^2) in bubble sort method 
C :: c atoi atof 
C :: data-types 
C :: how to convert c program in to assembly 8051 online 
C :: grep C hello world 
C :: Unix socket I/O primitives 
C :: remove every appearance of char without malloc in c 
C :: difference between %d and %i 
C :: list fiter octobercms 
C :: BEE/URI problem no 1181 solution in C 
C :: change no_turbo 
C :: string compare in c 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =