Skip to content

Instantly share code, notes, and snippets.

@SametSahin10
Created March 13, 2018 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SametSahin10/f803201eb2ff0b2b28db4749ae8f38ad to your computer and use it in GitHub Desktop.
Save SametSahin10/f803201eb2ff0b2b28db4749ae8f38ad to your computer and use it in GitHub Desktop.
C program to print all the numbers in a char array.
#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