Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
1.1 kB
2
Indexable
Never
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char num2let(int a);
char chkstr(char string[]);
int main(){
    char a[50];
    printf("Enter a set of numbers:");
    scanf("%[^\n]",a);
    while (chkstr(a)!= 1){
        printf("Enter a valid set of numbers:");
        scanf("%[^\n]",a);
    }
    printf("%s",a);
    puts("");
    for (int i=0;i<strlen(a);i++){
        if(isdigit(a[i])&&a[i+1]==' '){
          printf("%c",num2let(a[i]-'0'));
          i+=1;
        }
        else if(isdigit(a[i])&&a[i+1]=='\0'){
          printf("%c",num2let(a[i]-'0'));
        }
        else if ((isdigit(a[i]))&&(isdigit(a[i+1]))){
          printf("%c",num2let((a[i]-'0')+(a[i+1]-'0')));
          i+=2;
        }
    }
}
char num2let(int a){
    return a+'`';
  }
  
char chkstr(char string[]){
    int num=0;
    for (int i=0;i<strlen(string);i++){
        if (string[i]==' '){
            num+=1;
        }
        if (isdigit(string[i])){
            num+=1;
        }
    }
    if (num==strlen(string)){
        return 1;
    }
    else{
        return 0;
    }
}