こんにちは、構造全体を別の構造にコピーしようとしています。コンパイルすると、エラーが発生しません....印刷すると、ガベージ値が表示されます....ガイドしてください...ありがとう!
2 つの異なる関数で、値を追加して印刷しようとしています。私の最初の関数は「read_list」です...これで、ユーザーから学生の名前と挿入されたマークを取得しています。
私の2番目の機能は「print_list」です。この機能を使用して、学生の詳細を印刷しています。
C の構造体を使用した非常に興味深い例をいくつか見つけることができるチュートリアルに案内してください
#include<stdio.h>
typedef struct _student
{
char name[50];
unsigned int mark;
} student;
void print_list(student list[], int size);
void read_list(student list[], int size);
int main(void)
{
const int size = 3;
student list_first[size]; //first structre
student list_second[size]; //second structre of same type
read_list(list_first, size); //list_first structer fills with values
print_list(list_first, size); //to check i have printed it here
//Now as i knew that my first struct is filled with data .....so now i wanted to copy it
list_second[size] = list_first[size]; //cpoid from one struct to another
printf("Second list is copied from another struct: \n");
print_list(list_second, size); //Tried to print it here ....
system("pause");
return 0;
}
void read_list(student list[], int size)
{
unsigned int i;
printf("Please enter the info:\n");
for(i = 0; i<size; i++)
{
printf("\nname: ");
scanf("%s",&list[i].name);
printf("\nMark: ");
scanf("%d",&list[i].mark);
}
}
void print_list(student list[], int size)
{
unsigned int i;
for(i=0; i<size; i++)
{
printf("Name: %s\t %d\n",list[i].name,list[i].mark);
}
}