#include <stdio.h>

#include <stdlib.h>

int main()
{
int num[100]={0};
int i,n=0;
for(i=0; num[i] != EOF ; i++,n++)
{
scanf("%d",&num[i]);
}
printf("%d\n", i);
while(i=0;i<n;i++)
printf("%d ",num[i]);
printf("\n");
system("pause");
return 0;
}

That's my code that I wrote and the input shoul be 123 ctrl z and the out output should be 3 but the code that I wrote if I wrote an input it gives me 107 output....Can anyone help me to figure out the problem....

Sorry this is the one that I wrote with an error the first one is incorrect....

#include <stdio.h>
#include <stdlib.h>

int main()
{
int num[100]={0};
int i,n=0;
for(i=0; num[i] != EOF ; i++,n++)
{
scanf("%d",&num[i]);
}
printf("%d\n", i);
For(i=0;i<n;i++)
printf("%d ",num[i]);
printf("\n");
system("pause");
return 0;
}

Assistance needed.

The issue in your code lies within the condition `num[i] != EOF` in your `for` loop. In C, the `scanf` function returns the number of successfully read items, not the actual value itself. So, when you enter "123" followed by Ctrl + Z, `scanf` tries to read an integer and stores it in `num[i]`. Since it is successful in reading an integer, it returns 1 and the loop continues to execute.

To fix this issue, you need to modify your code as follows:

```c
#include <stdio.h>
#include <stdlib.h>

int main()
{
int num[100] = {0};
int i = 0;

while (scanf("%d", &num[i]) == 1)
{
i++;
}

printf("%d\n", i);

for (int j = 0; j < i; j++)
{
printf("%d ", num[j]);
}
printf("\n");

system("pause");
return 0;
}
```

In this modified code, the `while` loop reads integers using `scanf` and checks the return value. If `scanf` successfully reads an integer, i.e., it returns 1, it increments `i` and continues to read the next integer. If `scanf` encounters the end-of-file (EOF) or fails to read an integer, it stops reading and moves on to the printing loop.

Now, the code will correctly read the integers until it reaches EOF and then print the correct count `i` and the array values.