0

I want to write a program in c that takes the name of a student it's age and some grades and put those in a two dimensional array, i input the first name as BigFirstName , the last name as BigLastName, the age as 18, the math grade as 100, the physics grade 100, and the average of the two 100 but it dosen't print them out like that, instead it prints:

BigFirstBigLastN18
BigLastN18
18
100
100
100

Here is my code:

#include <stdio.h>

char *Grades[1][6];
int line=0;
int column=0;

int main(void) {
  printf("Input Firstname \n");
  scanf(" %s",&Grades[line][column]);
  column+=1;

  printf("Input Lastname \n");
  scanf(" %s",&Grades[line][column]);
  column+=1;

  printf("Input age ");
  scanf(" %s",&Grades[line][column]);
  column+=1;

  printf("Input Math Grade \n");
  scanf(" %s",&Grades[line][column]);
  column+=1;

  printf("Input Physics Grade \n");
  scanf(" %s",&Grades[line][column]);
  column+=1;

  printf("Input Average Bettween the two \n");
  scanf(" %s",&Grades[line][column]);
  column+=1;

  int p;
  for (p=0;p<7;p++){
    printf ("%s\n",&Grades[0][p]);
  }
  return 0;
}
FNS21
  • 1
  • `Grades` is a 2D arrays of ***pointer to*** `char`. – alk Jan 07 '18 at 14:39
  • 1
    Also you want to pump up the compiler's warning level and take the warnings issued seriously. – alk Jan 07 '18 at 14:40
  • Last not least: You might want to have 2nd look at how many iterations the `for`-loop is performing. – alk Jan 07 '18 at 14:41
  • 1
    You need to allocate some memory for your array in order to hold the strings. You've declared a 2D array of character pointers that point someplace in memory you haven't defined. – lurker Jan 07 '18 at 14:41

0 Answers0