मुझे structs की सरणी शुरू करने में समस्या आ रही है। मुझे यकीन नहीं है कि मैं इसे सही कर रहा हूं क्योंकि मुझे "असंगत सूचक प्रकार से प्रारंभिकता" & "असंगत सूचक प्रकार से असाइनमेंट" मिलता है। मैं कोड है जहाँ मैं इन चेतावनियों पाने में जोड़ा, और जब मैं struct से डेटा मुद्रित करने के लिए कोशिश मैं सिर्फ // सरणी प्रारंभसी - structs की सरणी शुरू करें
student** students = malloc(sizeof(student));
int x;
for(x = 0; x < numStudents; x++)
{
//here I get: "assignment from incompatible pointer type"
students[x] = (struct student*)malloc(sizeof(student));
}
int arrayIndex = 0;
ऐसे @@ ###
typedef struct
{
char* firstName;
char* lastName;
int day;
int month;
int year;
}student;
के रूप में कचरा मिल
// struct जोड़ने
//create student struct
//here I get: "initialization from incompatible pointer type"
student* newStudent = {"john", "smith", 1, 12, 1983};
//add it to the array
students[arrayIndex] = newStudent;
arrayIndex++;
आपका कोड गतिशील रूप से छात्र structs की एक सरणी बनाने और छात्र संरचनाओं के लिए पॉइंटर्स की एक सरणी बनाने के बीच आधा रास्ता लगता है, और फिर गतिशील रूप से प्रत्येक छात्र संरचना को बनाते हैं जो इंगित करता है। यह स्पष्ट नहीं है कि आप कौन सी कोशिश कर रहे हैं, जो इस मुश्किल का जवाब देता है। –