Hi All,

I have written a program to input a decimal string and convert it to character string. Below is my program:

``````/*this program converts the decimal representation of an input string to character representation*/
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
char int2str(int n);
int main()
{
int dec[100]={0},i,j,decindex,ndec=0,nchar;
char character[100]={'\0'};
printf("Enter the input decimal sequence length\n");
scanf("%d",&ndec);
printf("Enter the input decimal sequence\n");
for(i=0;i<=nchar;i++)
{
scanf("%d",&j);
dec[i]=j;
}
/*This loop converts the decimal to character*/
for(i=0;i<=nchar;i++)
{
if(dec[i]!='.')
{
character[i]=int2str(dec[i]);
}
}
printf("The output sequence is");
for(i=0;i<=nchar;i++)
{
printf("%c",character[i]);
}
system("pause");
return 0;
}

/*this loop converts the decimal to character*/
char int2str(int n)
{
char c;
c=n+48;
return c;
}
``````

On running the program, It doesn't proceed after entering the input decimal sequence. Kindly point out bugs/errors and suggest fixes. Thank you.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Ankit_Parmar

initialize the value of variable nchar

printf("Enter the input decimal sequence length\n");
**scanf("%d",&nchar); /* use 'nchar' Instead of 'ndec' ...your logic & program both will work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.