isalpha

Trouble implementing isalpha

ε祈祈猫儿з 提交于 2020-06-09 05:24:14
问题 I've been working on the readability problem in CS50. The first step is to create a way to count only the alphabetical characters. It suggests to use the isalpha function, but doesn't really include directions on how to implement it. Below is my code which succeeds in counting total alphabetical characters, but fails to filter out punctuation, spaces and integers. Could anyone point me in a better direction to implement the isalpha so that it functions? #include <stdio.h> #include <cs50.h>

Check if a string has only numbers in C?

旧巷老猫 提交于 2019-12-11 07:28:36
问题 I'm trying to write a simple code to check if a string only has numbers in it. So far it's not working, any help would be appreciated. #include <stdio.h> #include <string.h> #include <ctype.h> int main() { char numbers[10]; int i, correctNum = 0; scanf("%s", numbers); for(i = 0 ; i <= numbers ; ++i) { if(isalpha(numbers[i])) { correctNum = 1; break; } } if(correctNum == 1) { printf("That number has a char in it. FIX IT.\n"); } else { printf("All numbers. Good.\n"); } return 0; } 回答1: Adding