Onarıyorum!Yapıdaki diziye erişemiyorum
typedef struct student
{
char id[11];
}Student;
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv){
int input = 0, i = 0;
FILE * fp = fopen("student.txt", "wt");
if (fp == NULL) {
printf("Error to open student.txt");
return -1;
}
scanf("%d",&input);
student = (Student *)malloc(input*sizeof(Student));
for(i=0;i<input;i++){
strcpy(student[i].id, "a"); // A is just for default.
fprintf(fp,"%s\n",student[i].id);
}
fclose(fp);
return 0;
}
Yorumlardan ve türden yanıtlardan düzelttim. Ve yardım
içinTeşekkür çalışır
ben gerçekten takdir! Gerçekten faydalıydı.
Öğrenci nedir? –
Neden öğrenci = (Öğrenci *) malloc (input * sizeof (Öğrenci)); 'bir döngü içinde mi? Aynı göstergeye yeni bir adres atayacaksınız, ki boş bırakmamış olduğunuz önceki tahsisleri sızdırıyor olacak. – Michael
Lütfen [Minimal, Tam ve Doğrulanabilir örnek] (http://stackoverflow.com/help/mcve) –