I am trying to make two separate functions, one for a reading of an array, and another one for prining it. My code looks something like this:
#include <stdio.h>
#include <stdlib.h>
void read(int n, int v[100])
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&v[i]);
}
}
void print(int n, int v[100])
{
for(int i=0;i<n;i++)
{
printf("%d",v[i]);
}
}
int main()
{
int v[100];
int n;
read(n,v);
print(n,v);
}
But if i read something like this
5
1
2
3
4
5
it prints this:
12345167773430408951321408978481140419686004089785612740906704021677734340894
and other numbers. Any suggestions?
read(n,v);andprint(n,v);are using the uninitiaised variablen.%ddoesn't print any.read()return the count instead of using a pointer parameter.int v[100];printed invoid printis also unintialised. Please understand that local variables defined in a function have indeteminate value.