Hi Your code has many mistakes and loop holes, I will surely give you a better code but first of all I am just marking mistakes in code and just making your code ready to work. Go through all the comments in code and run this on your machine. This is a working code and help you to understand your mistakes.I checked this on turboC.
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct countOf
{
int current;
int count;//why??
struct countOf *next_ptr;//why, u r using continuous blocks
}countOfNode;
// typedef make countOfNode as an dataType
countOfNode *rep;
//Now rep is global pointer of type struct countOf
int main()
{
int arr[10];//why 9 while we have 10 count everywhere in code
int count = 10;
int i;
rep = (countOfNode*)malloc(count * sizeof(countOfNode));
printf("Enter 10 values in array if you want to assign value from array structure array");
for (i = 0; i < count; i++ )
{ clrscr();// to not keep useless on screen;
printf("Enter %dth value in array",i+1);
scanf("%d",&arr[i]);
}
for (i = 0; i < count; i++ )
{
/*any value you want to assign to current
but what is arr[i]??? it contains no value
*/
//rep->current = arr[i];
//Currently there is no next pointer
// rep = rep->next_ptr;
//You assign it 10 continuos blocks so what is the use of ptr???
//For pointer dont assign continuos blocks make it dynamic
rep[i].current = arr[i];
}
printf("Data in structure rep");
for(i=0 ; i<count; i++)
{
printf("%dth node have \t%d\n",i+1,rep[i].current);
}
}
Now you may check the below code with few improvements in your code, This one is not the best way, but it will help you to better understand. We can write code in far better way
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct countOf
{
int current;
struct countOf *next_ptr;//it keep address of next node
}countOfNode;
countOfNode *rep;
//Now rep is global pointer of type struct countOf we just keep offset(base address in this)
int main()
{
int count = 10;
int i;
countOfNode *tracker, *tmp;
rep = (countOfNode*)malloc(sizeof(countOfNode));//initializing first time
printf("Enter value To store");
scanf("%d",&rep->current);//storing value for first node
rep->next_ptr = NULL;//assigin null becaus there is no next node
tracker = rep; // we move tracker alway, rep will just keep the offset
for(i=1; i<count; i++)//0 already assigned above
{
tmp = (countOfNode*)malloc(sizeof(countOfNode));//initializing current node
printf("Enter value To store");
scanf("%d",&tmp->current);//storing value for first node
tmp->next_ptr = NULL;//assigin null becaus there is no next node
tracker->next_ptr = tmp; // we move tracker alway, rep will just keep the offset
tracker = tmp;//tracker jump to next node
}
printf("Data in structure rep");
tracker = rep;
for(i=0; i<count; i++)//0 already assigned above
{
printf("%d\t",tracker->current);
tracker = tracker->next_ptr;//jump to next
}
getch();
}