Created
March 13, 2018 12:59
-
-
Save SametSahin10/f803201eb2ff0b2b28db4749ae8f38ad to your computer and use it in GitHub Desktop.
C program to print all the numbers in a char array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
int main() { | |
char sentence[100]; | |
int numberOfNumbers = 0; | |
printf("\n\n"); | |
printf("Enter a sentence: "); | |
fgets(sentence, 100, stdin); | |
for(int i = 0; sentence[i] != '\0'; i++) { | |
if (isdigit(sentence[i]) != 0) { | |
numberOfNumbers++; | |
printf("%c\n",sentence[i]); | |
} | |
} | |
printf("\n"); | |
if (numberOfNumbers == 0) { | |
printf("There isn't any number at the sentence.\n"); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment