How do I use a users input to open a text file and then load it into a 2D array?
up vote
0
down vote
favorite
This is what I have in my text file.
6814,85,86,92,88
7234,76,81,84,78
6465,87,54,68,72
7899,92,90,88,86
9901,45,78,79,80
8234,77,87,84,98
7934,76,91,84,65
7284,56,81,87,98
7654,76,87,84,88
3534,86,81,84,73
And this is what I've coded.
void getName(float arr1[x][y])
FILE* graFile;
float arr2[x][y];
char userIn[50];
printf("Enter filename: ");
scanf("%s", userIn);
graFile = fopen(userIn, "r");
int studentId, test1, test2, test3, test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
fscanf(graFile, "%d%d%d%d%d%f", &studentId, &test1, &test2, &test3, &test4, &arr2[i][j]);
arr2[0][0] = studentId;
arr2[0][1] = test1;
arr2[0][2] = test2;
arr2[0][3] = test3;
arr2[0][4] = test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%f", arr2[i][j]);
printf("n");
fclose(graFile);
return;
I have to write a program that asks the user to input the name of a text file (which contains grades), then load it into a 2D array. Then I have to sort the grades and take the average of the grades. I'm starting with my first function, which is to get the user input for a text file name and load it into a 2D array. I'm still new to C programming and I'm having a hard time understanding 2D arrays. I appreciate any help I can get.
c arrays file
|
show 6 more comments
up vote
0
down vote
favorite
This is what I have in my text file.
6814,85,86,92,88
7234,76,81,84,78
6465,87,54,68,72
7899,92,90,88,86
9901,45,78,79,80
8234,77,87,84,98
7934,76,91,84,65
7284,56,81,87,98
7654,76,87,84,88
3534,86,81,84,73
And this is what I've coded.
void getName(float arr1[x][y])
FILE* graFile;
float arr2[x][y];
char userIn[50];
printf("Enter filename: ");
scanf("%s", userIn);
graFile = fopen(userIn, "r");
int studentId, test1, test2, test3, test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
fscanf(graFile, "%d%d%d%d%d%f", &studentId, &test1, &test2, &test3, &test4, &arr2[i][j]);
arr2[0][0] = studentId;
arr2[0][1] = test1;
arr2[0][2] = test2;
arr2[0][3] = test3;
arr2[0][4] = test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%f", arr2[i][j]);
printf("n");
fclose(graFile);
return;
I have to write a program that asks the user to input the name of a text file (which contains grades), then load it into a 2D array. Then I have to sort the grades and take the average of the grades. I'm starting with my first function, which is to get the user input for a text file name and load it into a 2D array. I'm still new to C programming and I'm having a hard time understanding 2D arrays. I appreciate any help I can get.
c arrays file
1
Please provide your code in text form in your post
– Yastanub
Nov 10 at 0:43
1
it is far, far easier for others to help when your source code and inputs and outputs are in the body of your question, as text, not as images; I have to think it would have been fewer steps for you, as well, to paste what is already text into the text of your question; also, please clarify exactly what isn't working
– landru27
Nov 10 at 0:44
Please post a Minimal, Complete, and Verifiable example of what you have tried and exactly why it is not doing what you want
– user3629249
Nov 10 at 0:50
arex
andy
global variables? MUCH better to modify the function signature to:void getarray( int x, int y, arry[y] )
– user3629249
Nov 10 at 0:53
1
regarding:arr2[0][0] = studentId; arr2[0][1] = test1; arr2[0][2] = test2; arr2[0][3] = test3; arr2[0][4] = test4;
This will always copy into the first record in thearr2
suggest:arr2[i][0] = studentId; arr2[i][1] = test1; arr2[i][2] = test2; arr2[i][3] = test3; arr2[i][4] = test4;
and when reading the data, this statement:for(int j = 0; j < y; j++) {
is not correct and should be removed
– user3629249
Nov 10 at 1:14
|
show 6 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is what I have in my text file.
6814,85,86,92,88
7234,76,81,84,78
6465,87,54,68,72
7899,92,90,88,86
9901,45,78,79,80
8234,77,87,84,98
7934,76,91,84,65
7284,56,81,87,98
7654,76,87,84,88
3534,86,81,84,73
And this is what I've coded.
void getName(float arr1[x][y])
FILE* graFile;
float arr2[x][y];
char userIn[50];
printf("Enter filename: ");
scanf("%s", userIn);
graFile = fopen(userIn, "r");
int studentId, test1, test2, test3, test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
fscanf(graFile, "%d%d%d%d%d%f", &studentId, &test1, &test2, &test3, &test4, &arr2[i][j]);
arr2[0][0] = studentId;
arr2[0][1] = test1;
arr2[0][2] = test2;
arr2[0][3] = test3;
arr2[0][4] = test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%f", arr2[i][j]);
printf("n");
fclose(graFile);
return;
I have to write a program that asks the user to input the name of a text file (which contains grades), then load it into a 2D array. Then I have to sort the grades and take the average of the grades. I'm starting with my first function, which is to get the user input for a text file name and load it into a 2D array. I'm still new to C programming and I'm having a hard time understanding 2D arrays. I appreciate any help I can get.
c arrays file
This is what I have in my text file.
6814,85,86,92,88
7234,76,81,84,78
6465,87,54,68,72
7899,92,90,88,86
9901,45,78,79,80
8234,77,87,84,98
7934,76,91,84,65
7284,56,81,87,98
7654,76,87,84,88
3534,86,81,84,73
And this is what I've coded.
void getName(float arr1[x][y])
FILE* graFile;
float arr2[x][y];
char userIn[50];
printf("Enter filename: ");
scanf("%s", userIn);
graFile = fopen(userIn, "r");
int studentId, test1, test2, test3, test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
fscanf(graFile, "%d%d%d%d%d%f", &studentId, &test1, &test2, &test3, &test4, &arr2[i][j]);
arr2[0][0] = studentId;
arr2[0][1] = test1;
arr2[0][2] = test2;
arr2[0][3] = test3;
arr2[0][4] = test4;
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%f", arr2[i][j]);
printf("n");
fclose(graFile);
return;
I have to write a program that asks the user to input the name of a text file (which contains grades), then load it into a 2D array. Then I have to sort the grades and take the average of the grades. I'm starting with my first function, which is to get the user input for a text file name and load it into a 2D array. I'm still new to C programming and I'm having a hard time understanding 2D arrays. I appreciate any help I can get.
c arrays file
c arrays file
edited Nov 10 at 0:59
asked Nov 10 at 0:39
Angie
12
12
1
Please provide your code in text form in your post
– Yastanub
Nov 10 at 0:43
1
it is far, far easier for others to help when your source code and inputs and outputs are in the body of your question, as text, not as images; I have to think it would have been fewer steps for you, as well, to paste what is already text into the text of your question; also, please clarify exactly what isn't working
– landru27
Nov 10 at 0:44
Please post a Minimal, Complete, and Verifiable example of what you have tried and exactly why it is not doing what you want
– user3629249
Nov 10 at 0:50
arex
andy
global variables? MUCH better to modify the function signature to:void getarray( int x, int y, arry[y] )
– user3629249
Nov 10 at 0:53
1
regarding:arr2[0][0] = studentId; arr2[0][1] = test1; arr2[0][2] = test2; arr2[0][3] = test3; arr2[0][4] = test4;
This will always copy into the first record in thearr2
suggest:arr2[i][0] = studentId; arr2[i][1] = test1; arr2[i][2] = test2; arr2[i][3] = test3; arr2[i][4] = test4;
and when reading the data, this statement:for(int j = 0; j < y; j++) {
is not correct and should be removed
– user3629249
Nov 10 at 1:14
|
show 6 more comments
1
Please provide your code in text form in your post
– Yastanub
Nov 10 at 0:43
1
it is far, far easier for others to help when your source code and inputs and outputs are in the body of your question, as text, not as images; I have to think it would have been fewer steps for you, as well, to paste what is already text into the text of your question; also, please clarify exactly what isn't working
– landru27
Nov 10 at 0:44
Please post a Minimal, Complete, and Verifiable example of what you have tried and exactly why it is not doing what you want
– user3629249
Nov 10 at 0:50
arex
andy
global variables? MUCH better to modify the function signature to:void getarray( int x, int y, arry[y] )
– user3629249
Nov 10 at 0:53
1
regarding:arr2[0][0] = studentId; arr2[0][1] = test1; arr2[0][2] = test2; arr2[0][3] = test3; arr2[0][4] = test4;
This will always copy into the first record in thearr2
suggest:arr2[i][0] = studentId; arr2[i][1] = test1; arr2[i][2] = test2; arr2[i][3] = test3; arr2[i][4] = test4;
and when reading the data, this statement:for(int j = 0; j < y; j++) {
is not correct and should be removed
– user3629249
Nov 10 at 1:14
1
1
Please provide your code in text form in your post
– Yastanub
Nov 10 at 0:43
Please provide your code in text form in your post
– Yastanub
Nov 10 at 0:43
1
1
it is far, far easier for others to help when your source code and inputs and outputs are in the body of your question, as text, not as images; I have to think it would have been fewer steps for you, as well, to paste what is already text into the text of your question; also, please clarify exactly what isn't working
– landru27
Nov 10 at 0:44
it is far, far easier for others to help when your source code and inputs and outputs are in the body of your question, as text, not as images; I have to think it would have been fewer steps for you, as well, to paste what is already text into the text of your question; also, please clarify exactly what isn't working
– landru27
Nov 10 at 0:44
Please post a Minimal, Complete, and Verifiable example of what you have tried and exactly why it is not doing what you want
– user3629249
Nov 10 at 0:50
Please post a Minimal, Complete, and Verifiable example of what you have tried and exactly why it is not doing what you want
– user3629249
Nov 10 at 0:50
are
x
and y
global variables? MUCH better to modify the function signature to: void getarray( int x, int y, arry[y] )
– user3629249
Nov 10 at 0:53
are
x
and y
global variables? MUCH better to modify the function signature to: void getarray( int x, int y, arry[y] )
– user3629249
Nov 10 at 0:53
1
1
regarding:
arr2[0][0] = studentId; arr2[0][1] = test1; arr2[0][2] = test2; arr2[0][3] = test3; arr2[0][4] = test4;
This will always copy into the first record in the arr2
suggest: arr2[i][0] = studentId; arr2[i][1] = test1; arr2[i][2] = test2; arr2[i][3] = test3; arr2[i][4] = test4;
and when reading the data, this statement: for(int j = 0; j < y; j++) {
is not correct and should be removed– user3629249
Nov 10 at 1:14
regarding:
arr2[0][0] = studentId; arr2[0][1] = test1; arr2[0][2] = test2; arr2[0][3] = test3; arr2[0][4] = test4;
This will always copy into the first record in the arr2
suggest: arr2[i][0] = studentId; arr2[i][1] = test1; arr2[i][2] = test2; arr2[i][3] = test3; arr2[i][4] = test4;
and when reading the data, this statement: for(int j = 0; j < y; j++) {
is not correct and should be removed– user3629249
Nov 10 at 1:14
|
show 6 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
the following proposed code:
- cleanly compiles
- performs the desired functionality
- properly 'types' variables for the expected input
- properly checks for errors
- uses
puts()
when appropriate - properly outputs error messages to
stderr
- avoids unnecessary variable declarations and data copying
- consistently indents the code
- uses horizontal spacing, when appropriate, for readability
- properly uses a format string in calls to
printf()
- separates code blocks:
for
if
else
while
do...while
switch
case
,default
via a single blank line, for readability
and now, the proposed code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_FILENAME_LEN 50
void getName( int x, int y )
int arr2[x][y];
char userIn[ MAX_FILENAME_LEN ];
FILE* graFile;
printf("%s", "Enter filename: ");
if( scanf("%49s", userIn) != 1)
fprintf( stderr, "scanf failed to read file namen" );
exit( EXIT_FAILURE );
// implied else, scanf successful
graFile = fopen(userIn, "r");
if( !graFile )
perror( "fopen failed" );
exit( EXIT_FAILURE );
// implied else, fopen successful
for(int i = 0; i < x; i++)
if( fscanf( graFile,
"%d%d%d%d%d",
&arr2[i][0],
&arr2[i][1],
&arr2[i][2],
&arr2[i][3],
&arr2[i][4] ) != 5 )
fclose( graFile );
fprintf( stderr, "fscanf failed to read row %d from the input filen", i );
exit( EXIT_FAILURE );
fclose(graFile);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%d", arr2[i][j]);
puts( "" );
Thank you! This helped me out a lot. If I wanted to keep repeating the program until the user entered the correct file name, how could I do that? I know I would need a while loop but I'm not sure where to put it.
– Angie
Nov 10 at 6:40
Nit "usesputs()
when appropriate", presuming you meanputs( "" );
Why are you using a string function to output a single char? Perhapsputchar ('n');
for a single character? Also, better to explain that OP got wrong (though your answer clearly helped).
– David C. Rankin
Nov 10 at 7:25
@Angie - short example, Read from filename given as argument, or prompt until valid filename given
– David C. Rankin
Nov 10 at 8:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
the following proposed code:
- cleanly compiles
- performs the desired functionality
- properly 'types' variables for the expected input
- properly checks for errors
- uses
puts()
when appropriate - properly outputs error messages to
stderr
- avoids unnecessary variable declarations and data copying
- consistently indents the code
- uses horizontal spacing, when appropriate, for readability
- properly uses a format string in calls to
printf()
- separates code blocks:
for
if
else
while
do...while
switch
case
,default
via a single blank line, for readability
and now, the proposed code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_FILENAME_LEN 50
void getName( int x, int y )
int arr2[x][y];
char userIn[ MAX_FILENAME_LEN ];
FILE* graFile;
printf("%s", "Enter filename: ");
if( scanf("%49s", userIn) != 1)
fprintf( stderr, "scanf failed to read file namen" );
exit( EXIT_FAILURE );
// implied else, scanf successful
graFile = fopen(userIn, "r");
if( !graFile )
perror( "fopen failed" );
exit( EXIT_FAILURE );
// implied else, fopen successful
for(int i = 0; i < x; i++)
if( fscanf( graFile,
"%d%d%d%d%d",
&arr2[i][0],
&arr2[i][1],
&arr2[i][2],
&arr2[i][3],
&arr2[i][4] ) != 5 )
fclose( graFile );
fprintf( stderr, "fscanf failed to read row %d from the input filen", i );
exit( EXIT_FAILURE );
fclose(graFile);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%d", arr2[i][j]);
puts( "" );
Thank you! This helped me out a lot. If I wanted to keep repeating the program until the user entered the correct file name, how could I do that? I know I would need a while loop but I'm not sure where to put it.
– Angie
Nov 10 at 6:40
Nit "usesputs()
when appropriate", presuming you meanputs( "" );
Why are you using a string function to output a single char? Perhapsputchar ('n');
for a single character? Also, better to explain that OP got wrong (though your answer clearly helped).
– David C. Rankin
Nov 10 at 7:25
@Angie - short example, Read from filename given as argument, or prompt until valid filename given
– David C. Rankin
Nov 10 at 8:12
add a comment |
up vote
0
down vote
the following proposed code:
- cleanly compiles
- performs the desired functionality
- properly 'types' variables for the expected input
- properly checks for errors
- uses
puts()
when appropriate - properly outputs error messages to
stderr
- avoids unnecessary variable declarations and data copying
- consistently indents the code
- uses horizontal spacing, when appropriate, for readability
- properly uses a format string in calls to
printf()
- separates code blocks:
for
if
else
while
do...while
switch
case
,default
via a single blank line, for readability
and now, the proposed code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_FILENAME_LEN 50
void getName( int x, int y )
int arr2[x][y];
char userIn[ MAX_FILENAME_LEN ];
FILE* graFile;
printf("%s", "Enter filename: ");
if( scanf("%49s", userIn) != 1)
fprintf( stderr, "scanf failed to read file namen" );
exit( EXIT_FAILURE );
// implied else, scanf successful
graFile = fopen(userIn, "r");
if( !graFile )
perror( "fopen failed" );
exit( EXIT_FAILURE );
// implied else, fopen successful
for(int i = 0; i < x; i++)
if( fscanf( graFile,
"%d%d%d%d%d",
&arr2[i][0],
&arr2[i][1],
&arr2[i][2],
&arr2[i][3],
&arr2[i][4] ) != 5 )
fclose( graFile );
fprintf( stderr, "fscanf failed to read row %d from the input filen", i );
exit( EXIT_FAILURE );
fclose(graFile);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%d", arr2[i][j]);
puts( "" );
Thank you! This helped me out a lot. If I wanted to keep repeating the program until the user entered the correct file name, how could I do that? I know I would need a while loop but I'm not sure where to put it.
– Angie
Nov 10 at 6:40
Nit "usesputs()
when appropriate", presuming you meanputs( "" );
Why are you using a string function to output a single char? Perhapsputchar ('n');
for a single character? Also, better to explain that OP got wrong (though your answer clearly helped).
– David C. Rankin
Nov 10 at 7:25
@Angie - short example, Read from filename given as argument, or prompt until valid filename given
– David C. Rankin
Nov 10 at 8:12
add a comment |
up vote
0
down vote
up vote
0
down vote
the following proposed code:
- cleanly compiles
- performs the desired functionality
- properly 'types' variables for the expected input
- properly checks for errors
- uses
puts()
when appropriate - properly outputs error messages to
stderr
- avoids unnecessary variable declarations and data copying
- consistently indents the code
- uses horizontal spacing, when appropriate, for readability
- properly uses a format string in calls to
printf()
- separates code blocks:
for
if
else
while
do...while
switch
case
,default
via a single blank line, for readability
and now, the proposed code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_FILENAME_LEN 50
void getName( int x, int y )
int arr2[x][y];
char userIn[ MAX_FILENAME_LEN ];
FILE* graFile;
printf("%s", "Enter filename: ");
if( scanf("%49s", userIn) != 1)
fprintf( stderr, "scanf failed to read file namen" );
exit( EXIT_FAILURE );
// implied else, scanf successful
graFile = fopen(userIn, "r");
if( !graFile )
perror( "fopen failed" );
exit( EXIT_FAILURE );
// implied else, fopen successful
for(int i = 0; i < x; i++)
if( fscanf( graFile,
"%d%d%d%d%d",
&arr2[i][0],
&arr2[i][1],
&arr2[i][2],
&arr2[i][3],
&arr2[i][4] ) != 5 )
fclose( graFile );
fprintf( stderr, "fscanf failed to read row %d from the input filen", i );
exit( EXIT_FAILURE );
fclose(graFile);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%d", arr2[i][j]);
puts( "" );
the following proposed code:
- cleanly compiles
- performs the desired functionality
- properly 'types' variables for the expected input
- properly checks for errors
- uses
puts()
when appropriate - properly outputs error messages to
stderr
- avoids unnecessary variable declarations and data copying
- consistently indents the code
- uses horizontal spacing, when appropriate, for readability
- properly uses a format string in calls to
printf()
- separates code blocks:
for
if
else
while
do...while
switch
case
,default
via a single blank line, for readability
and now, the proposed code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_FILENAME_LEN 50
void getName( int x, int y )
int arr2[x][y];
char userIn[ MAX_FILENAME_LEN ];
FILE* graFile;
printf("%s", "Enter filename: ");
if( scanf("%49s", userIn) != 1)
fprintf( stderr, "scanf failed to read file namen" );
exit( EXIT_FAILURE );
// implied else, scanf successful
graFile = fopen(userIn, "r");
if( !graFile )
perror( "fopen failed" );
exit( EXIT_FAILURE );
// implied else, fopen successful
for(int i = 0; i < x; i++)
if( fscanf( graFile,
"%d%d%d%d%d",
&arr2[i][0],
&arr2[i][1],
&arr2[i][2],
&arr2[i][3],
&arr2[i][4] ) != 5 )
fclose( graFile );
fprintf( stderr, "fscanf failed to read row %d from the input filen", i );
exit( EXIT_FAILURE );
fclose(graFile);
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
printf("%d", arr2[i][j]);
puts( "" );
answered Nov 10 at 1:45
user3629249
10.8k1914
10.8k1914
Thank you! This helped me out a lot. If I wanted to keep repeating the program until the user entered the correct file name, how could I do that? I know I would need a while loop but I'm not sure where to put it.
– Angie
Nov 10 at 6:40
Nit "usesputs()
when appropriate", presuming you meanputs( "" );
Why are you using a string function to output a single char? Perhapsputchar ('n');
for a single character? Also, better to explain that OP got wrong (though your answer clearly helped).
– David C. Rankin
Nov 10 at 7:25
@Angie - short example, Read from filename given as argument, or prompt until valid filename given
– David C. Rankin
Nov 10 at 8:12
add a comment |
Thank you! This helped me out a lot. If I wanted to keep repeating the program until the user entered the correct file name, how could I do that? I know I would need a while loop but I'm not sure where to put it.
– Angie
Nov 10 at 6:40
Nit "usesputs()
when appropriate", presuming you meanputs( "" );
Why are you using a string function to output a single char? Perhapsputchar ('n');
for a single character? Also, better to explain that OP got wrong (though your answer clearly helped).
– David C. Rankin
Nov 10 at 7:25
@Angie - short example, Read from filename given as argument, or prompt until valid filename given
– David C. Rankin
Nov 10 at 8:12
Thank you! This helped me out a lot. If I wanted to keep repeating the program until the user entered the correct file name, how could I do that? I know I would need a while loop but I'm not sure where to put it.
– Angie
Nov 10 at 6:40
Thank you! This helped me out a lot. If I wanted to keep repeating the program until the user entered the correct file name, how could I do that? I know I would need a while loop but I'm not sure where to put it.
– Angie
Nov 10 at 6:40
Nit "uses
puts()
when appropriate", presuming you mean puts( "" );
Why are you using a string function to output a single char? Perhaps putchar ('n');
for a single character? Also, better to explain that OP got wrong (though your answer clearly helped).– David C. Rankin
Nov 10 at 7:25
Nit "uses
puts()
when appropriate", presuming you mean puts( "" );
Why are you using a string function to output a single char? Perhaps putchar ('n');
for a single character? Also, better to explain that OP got wrong (though your answer clearly helped).– David C. Rankin
Nov 10 at 7:25
@Angie - short example, Read from filename given as argument, or prompt until valid filename given
– David C. Rankin
Nov 10 at 8:12
@Angie - short example, Read from filename given as argument, or prompt until valid filename given
– David C. Rankin
Nov 10 at 8:12
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234997%2fhow-do-i-use-a-users-input-to-open-a-text-file-and-then-load-it-into-a-2d-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please provide your code in text form in your post
– Yastanub
Nov 10 at 0:43
1
it is far, far easier for others to help when your source code and inputs and outputs are in the body of your question, as text, not as images; I have to think it would have been fewer steps for you, as well, to paste what is already text into the text of your question; also, please clarify exactly what isn't working
– landru27
Nov 10 at 0:44
Please post a Minimal, Complete, and Verifiable example of what you have tried and exactly why it is not doing what you want
– user3629249
Nov 10 at 0:50
are
x
andy
global variables? MUCH better to modify the function signature to:void getarray( int x, int y, arry[y] )
– user3629249
Nov 10 at 0:53
1
regarding:
arr2[0][0] = studentId; arr2[0][1] = test1; arr2[0][2] = test2; arr2[0][3] = test3; arr2[0][4] = test4;
This will always copy into the first record in thearr2
suggest:arr2[i][0] = studentId; arr2[i][1] = test1; arr2[i][2] = test2; arr2[i][3] = test3; arr2[i][4] = test4;
and when reading the data, this statement:for(int j = 0; j < y; j++) {
is not correct and should be removed– user3629249
Nov 10 at 1:14