how to convert an char array to decimal array

Answers were Sorted based on User's Feedback



how to convert an char array to decimal array..

Answer / yogesh

#include<stdio.h>
int main()
{
char str[40],*s;
char ch,ask;
do
{
s=str;
printf("Enter the string:");
fgets(str,40,stdin);
do
{
printf("%d ",*s++);
}while(*s);
printf("\nDo u want to enter another string
(y/n):");
ask=getchar();
if(ask=='n')
break;
}while((ch=getchar())!='n');
printf("\n");
}

Is This Answer Correct ?    1 Yes 0 No

how to convert an char array to decimal array..

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
char a1[50];
int a2[50];
printf("enter the characters :");
gets(a1);
for(int i=0;a1[i]!='\0';i++)
a2[i]=(int)a1[i]; // TYPE CASTING
for(i=0;a1[i]!='\0';i++)
printf("%d",a2[i]);
getch();
}


thank you

Is This Answer Correct ?    2 Yes 2 No

how to convert an char array to decimal array..

Answer / raj

main()
{
int a[5];
char c[5]={'1','2','3','4','5'};
int i;
for(i=0;i<5;i++)
a[i]=c[i]-'0';
for(i=0;i<5;i++)
printf("%d ",a[i]);
}

Is This Answer Correct ?    0 Yes 0 No

how to convert an char array to decimal array..

Answer / kanakaraju

#include< stdio.h>
#include<conio.h>
main()
{
int a[5];
char c[5]={'1','2','3','4','5'};
int i;
for(i=0;i<5;i++)
a[i]=c[i]-'0';
for(i=0;i<5;i++)
printf("%d ",a[i]);
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

How to explain the final year project as a fresher please answer with sample project

0 Answers  


WHAT IS ABSTRACT DATA TYPE

4 Answers   Wipro,


Ca some one please help me with aC code to allow user enter numbers from 1 to 20 without repeating and prnt the sum of those numbers thnx

4 Answers  


what is the difference between i++ and ++i?

5 Answers  


Explain what is meant by 'bit masking'?

0 Answers  






Is using exit() the same as using return?

0 Answers  


What is the difference between new and malloc functions?

0 Answers   InterGraph,


write a programe to find the factorial of given number using recursion

3 Answers  


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

0 Answers  


What are the two types of functions in c?

0 Answers  


What is the mean of function?

0 Answers  


There are 21 people in a room. They have to form groups of 3 people each. How many combinations are possible? Write a C program to print the same.

1 Answers   HCL, iGate,


Categories