Note that there are some explanatory texts on larger screens.

plurals
  1. POPointer to structure
    primarykey
    data
    text
    <p>I am new to pointers and trying to use a pointer to the structure. But after the first entry, my program crashes. Kindly assist me.</p> <p>Here's the structure definition: </p> <pre><code>struct students{//structure students definition char name[20]; char RegNo[15]; char CourseUnit[10]; int score; char grade; }; </code></pre> <p>The grade should not be entered by the user but instead computed by the program. </p> <p>Here's my code so far I have written:</p> <pre><code>int main()//start of main { struct students *myStudPtr,myStud[SIZE]; myStudPtr=&amp;myStud[SIZE]; int i;//declare variables int count; printf("How many students do you want to deal with?\n"); scanf("%d",&amp;i);//number of entries for(count=1;count&lt;=i;count++) { printf("Enter student's name\n"); scanf("%s",&amp;(*myStudPtr).name); printf("Enter the student's registration number\n"); scanf("%s",&amp;(*myStudPtr).RegNo); printf("Enter the course unit\n"); scanf("%s",&amp;(*myStudPtr).CourseUnit); printf("Enter the marks scored\n"); scanf("%d",&amp;(*myStudPtr).score); } printf("NAME\tREGISTRATION\t\tCOURSE UNIT\tSCORE\t\tGRADE\n");//tabulates the output printf("%s\t", myStudPtr-&gt;name); printf("%s\t\t", myStudPtr-&gt;RegNo); printf("%s\t", myStudPtr-&gt;CourseUnit); printf("%d\t\t", myStudPtr-&gt;score); if(myStudPtr-&gt;score&gt;100) { printf("Invalid\n"); } else if(myStudPtr-&gt;score&lt;40) { printf("FAIL\n"); } else if(myStudPtr-&gt;score&lt;50) { printf("D\n"); } else if(myStudPtr-&gt;score&lt;60) { printf("C\n"); } else if(myStudPtr-&gt;score&lt;70) { printf("B\n"); } else if(myStudPtr-&gt;score&gt;70) { printf("A\n"); } else { printf("Invalid"); } return 0; } </code></pre> <p>Kindly assist.Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload