The problem is near break statement, Your break statement is being executed without executing a++;
. Here is the correct code.
#include<stdio.h>
#include<string.h>
void main()
{
int a=0, copy[10]={0},len,i;
char string[10];
clrscr();
puts("enter a number string");
gets(string);
len=strlen(string);
while(a<len)
{
for(i=48;i<=57;i++)
{
if(string[a]==i)
{
copy[a]=i-48;
a++;
break;
}
}
}
for(i=0;i<len;i++)
printf("%d",copy[i]);
getch();
}
solved this c program is not giving correct output.(to convert number string to integer) [duplicate]