Note that there are some explanatory texts on larger screens.

plurals
  1. POc- Strange behavior after getting inputs
    primarykey
    data
    text
    <p>I have to make a program that gets as an input a and b, gets as input a number "a" of lines of the following form: "studentId studentName studentPhone" and b lines of input in the form "stId mark1 mark2 mark3". The program then outputs all the stid from the first input and if the same id exists in input b the program outputs the students marks besides its id.</p> <p>I've gone through hell to getting the input properly and I think this is close but I get a strange behavior: after I input the marks in the second input it seems like some of the student ids in the first input are changed. </p> <p>This is my code: (here i try to input just the student IDs. <a href="http://ideone.com/dBYzwe" rel="nofollow">http://ideone.com/dBYzwe</a> )</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;malloc.h&gt; void chomp(char *s); struct listA{ int stId; char stName[19]; char stPhone[12]; }; struct listB{ int stId; char marks[11]; }; int main(void) { int i, j, m, n; scanf("%d%d", &amp;m, &amp;n); struct listA *a = malloc(sizeof(m * sizeof(struct listA))); struct listB *b = malloc(sizeof(n * sizeof(struct listB))); for(i = 0; i &lt; m; i++) { scanf("%d", &amp;a[i].stId); fgets(a[i].stName, 19, stdin); fgets(a[i].stPhone, 11, stdin); chomp(a[i].stName); chomp(a[i].stPhone); } for(i = 0; i &lt; m; i++) printf("%d ", a[i].stId); for(i = 0; i &lt; n; i++) { scanf("%d ", &amp;b[i].stId); fgets(b[i].marks, 12, stdin); fflush(stdin); } printf("\n"); for(i = 0; i &lt; n; i++) { printf("%d ", b[i].stId); } printf("\n"); for(i = 0; i &lt; m; i++) printf("%d ", a[i].stId); return 0; } void chomp(char *s) { while(*s &amp;&amp; *s != '\n' &amp;&amp; *s != '\r') s++; *s = 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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