Write a C program to convert character array to integer array.
#include <string.h>
int main() {
int i = 0;
char string[100];
/* get the input string from the user */
printf("Enter your input string:");
fgets(string, 100, stdin);
string[strlen(string) - 1] = '\0';
/* printing the character array */
printf("\nInput character array: {");
while (string[i] != '\0') {
printf("%c", string[i]);
if (string[i + 1] != '\0')
printf(", ");
i++;
}
printf("}\n");
i = 0;
/* print the equivalent integer array */
printf("Equivalent Integer Array: {");
while (string[i] != '\0') {
printf("%d", toascii(string[i]));
if (string[i + 1] != '\0')
printf(", ");
i++;
}
printf("}\n");
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input string: JaiHind
Input character array: {J, a, i, H, i, n, d}
Equivalent Integer Array: {74, 97, 105, 72, 105, 110, 100}
Enter your input string: JaiHind
Input character array: {J, a, i, H, i, n, d}
Equivalent Integer Array: {74, 97, 105, 72, 105, 110, 100}
No comments:
Post a Comment