Get a string from the user, and store the ascii value of each of the character of the string in a seperate integer array.
For example:
If the input string is
"sathish"
the resultant ascii array is
115 97 116 104 105 115 104
Implementation:
For example:
If the input string is
"sathish"
the resultant ascii array is
115 97 116 104 105 115 104
Implementation:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
/* Character pointer to point to starting character of the string */
char *s;
int i,*a,j;
/* Dynamically allocate the memory for string / character array */
s=(char*)malloc(sizeof(char));
/* Dynamically allocate memory for integer array */
a=(int*)malloc(sizeof(int));
/* Get the input string from the user */
scanf("%s",s);
/* Until we reach the end of the string, which is a null character '\0' of macro constant 0 */
while(*(s+i))
{
/* store each character's ascii value in the array a */
*(a+i)=(int)*(s+i);
i++;
}
/* Print the array which has the ascii values of characters of the string */
for(j=0;j<i;j++)
printf("%d ",*(a+j));
return 0;
}