hi I'm wanting to convert alphabet to numbers as in a == 1, b == 2. Instead I get asci, so i want to subtract 96. like so:
Code:
#include<stdio.h>
#include<ctype.h>
#define MAXSTRING 100
int main()
{
char c,name[MAXSTRING];
int i, sum = 0;
printf("\nhello! What is your name? ");
for (i = 0 ;(c = getchar()) != '\n'; ++i){
name[i] = c;
if (isalpha(c))
//sum += c;
sum += (c - 96);
}
name[i]='\0';
printf("\n%s%s%s\n%s",
"hi ", name, ".",
"Your name spelt backward is ");
for(--i ; i >=0 ; --i)
putchar(name[i]);
printf("\n%s%d%s\n\n%s\n",
"and the letters in your name sum to ", sum, ".",
"have a nice day\n");
return 0;
}