Hi, i'am trying to take info about student as an input and store it into a file, i got a probelm with taking a name, basically what i'am trying to do is allocate more memory to first_name[0]/last_name[0] so they can store string. Can you give a hand with what is the problem with a code? Thanks.
CODE:
Code:
char first_name[3];
char* ptr_first = &first_name[0];
ptr_first = (char*)malloc(100 * sizeof(char));
char last_name[3];
char* ptr_last = &last_name[0];
ptr_last = (char*)malloc(100 * sizeof(char));
float grade_test;
float grade_excercise;
char grade_final[5];
printf("First name: ");
scanf_s("%s", &ptr_first);
printf("Last name: ");
scanf_s("%c", &ptr_last);
printf("Grade-test: ");
scanf_s("%f", &grade_test);
printf("Grade-excercise: ");
scanf_s("%f", &grade_excercise);
printf("Grade-test: ");
scanf_s("%c", &grade_final);
FILE* ptr;
fopen_s(&ptr,"index.txt", "w");
fprintf(ptr, "[%s,%s,%f,%f]\n",*ptr_first,*ptr_last,grade_test,grade_excercise);
fclose(ptr);