sequence of letters and points in c

Asked

Viewed 45 times

-1

I need to make a program that compares several strings, I already tried to make one switch but it didn’t work because it only accepts a comparison character. I need each dot to represent a letter, example:

a .
b ..
c ...
d ... .

That’s what I could do:

#include <stdio.h>
#include <stdlib.h>
    
int main () {
    char letra;
    printf("Digite os pontos:");
    scanf("%s",&letra);
    switch (letra){
    
        case '..':
            printf("a\n");
        break;
        
        case '..':
            printf("b\n");
        break;
    }
    
    system("pause");
    return 0;
}

1 answer

0

The best way for you to implement this is:

1 - Get the string with the dots (your code is already wrong because it puts on a char where only one fits '.');

2 - printf("Letter: %c", strlen(string_com_points) + 0x60);

With this simple printf line you turn x points '.' into a corresponding tiny ASCII. Obviously you need to put protections for maximum points and none, but it is very quiet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.