How to write a C Program String Example in C Programming Language ?
Solution For C Program :
//C Program String Example.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(){
while( 1 ){
char s[1000];
gets(s);
if( strcmp(s, "0") == 0 ){
break;
}
int sum = 0;
int i;
for( i = 0 ; s[i] != '\0' ; i++ ){
if( isalpha(s[i]) ){
sum += tolower(s[i]) - 'a' + 1;
}
else {
sum = -1;
break;
}
}
if( sum == -1 ){
printf("Fail\n");
}
else {
printf("%d\n", sum);
}
}
return 0;
}