Write a C program to convert string to ASCII values.
#include <string.h>
int main () {
int i = 0;
char str[100];
printf("Enter your input string:");
fgets(str, 100, stdin);
str[strlen(str) - 1] ='\0';
while (str[i] != 0) {
printf("%c -> %d", str[i], toascii(str[i]));
printf("\n");
i++;
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input string:helloworld
h -> 104
e -> 101
l -> 108
l -> 108
o -> 111
w -> 119
o -> 111
r -> 114
l -> 108
d -> 100
Enter your input string:helloworld
h -> 104
e -> 101
l -> 108
l -> 108
o -> 111
w -> 119
o -> 111
r -> 114
l -> 108
d -> 100
No comments:
Post a Comment