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

main() { intj; while9j<=10) { printf("\n%d",j); j=j+1; } }

4 Answers  


why i join syntel?

23 Answers   ABC, Syntel, TCS,


inline function is there in c language?

4 Answers  


What are qualifiers and modifiers c?

0 Answers  


What is the scope of static variable in c?

0 Answers  






What will happen when freeing memory twice

2 Answers  


main() { int i; printf("%d", &i)+1; scanf("%d", i)-1; }

1 Answers  


What character terminates all strings composed of character arrays? 1) 0 2) . 3) END

3 Answers  


Give a fast way to multiply a number by 7

15 Answers   Accenture, Aricent, Microsoft,


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

0 Answers   TCS,


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers  


Two's compliment of -5

4 Answers   Adobe,


Categories