I'm trying to get this code working properly. I'm just learning pointers and I'm still confused. I've tried to write this program as best I can but I'm still getting a few errors and because I'm new at this, I don't know how to debug it or if I'm even on the right track
pseudo-code:
Find out how many student names (and grades) are to be entered
Allocate the names and grades arrays
Prompt for and read the names and grades
Read the name into a temporary string
Allocate memory big enough to hold the name
Copy the name from the temporary string to the allocated string
Read the grade
Print the names and grades
Free the memory we allocated
Code:
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#define ArraySize 10
#define MaxNameLength 512
int main(int argc, char** argv)
{
char name[MaxNameLength +1];
char *studentNames = name;
int numNames;
float grade;
int i;
studentNames =malloc(MaxNameLength * sizeof(char));
printf( "Enter the number of students (1-10): ");
fgets(numNames, MaxNameLength, stdin);
printf( "Enter the %d names and grades: /n", numNames);
for (i = 0; i < numNames[i]; i++)
{
printf( "Name %d: %s/n", i, numNames[i]);
printf( "Grade %d: %.2f/n", i, grade[i]);
}
free(studentNames);
studentNames = NULL;
return ( 0 );
}
Any help is appreciated