Commit 4b64104a by emonyi

Upload New File

parent a53f4300
Showing with 52 additions and 0 deletions
#include <stdio.h>
#include <string.h>
int ident(char str[5]);
int convertToInteger(char str[5]);
int main(){
char input[5];
int count = 0;
do{
if(count > 0){
printf("This is not a number!\n");
}
puts("Enter a 5 digit number: ");
scanf("%s", input);
printf("String: %s", input);
printf("\n");
count ++;
}while(ident(input) != 5);
printf("Integer: %d\n", convertToInteger(input));
return 0;
}
int ident(char str[5]){
int flag;
int result = 0;
for(int i = 0; i < 5; i++){
flag = 0;
for(int j = 48; j <= 57; j++){
if(str[i] == j){
flag = 1;
break;
}
}
result = result + flag;
}
return result;
}
int convertToInteger(char str[5]){
int i, len;
int result=0;
len = 5;
for(i=0; i<len; i++){
result = result * 10 + ( str[i] - '0' );
}
return result;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment