Skip to content

Instantly share code, notes, and snippets.

@tarcisio-marinho
Created October 25, 2016 05:26
Show Gist options
  • Save tarcisio-marinho/42d1b45111c5d9dc917398168cb9d7bf to your computer and use it in GitHub Desktop.
Save tarcisio-marinho/42d1b45111c5d9dc917398168cb9d7bf to your computer and use it in GitHub Desktop.
Valida placa de carro
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void lerPlaca(char placa[]);
void validaPlaca(char placa[]);
void isnum(char caracter);
int main(){
char placa[8];
lerPlaca(placa);
validaPlaca(placa);
return 0;
}
void lerPlaca(char placa[]){
int i=0;
printf("Digite a placa, sendo os 3 primeiros caracteres letras e os 4 restantes numeros: \n\n");
for(i=0;i<=6;i++){
placa[i]=getche();
}
placa[8]='\0';
}
void validaPlaca(char placa[]){
int i,k,j,correto=0;
for(i=0;i<=2;i++){
k=isalpha(placa[i]);
if(k!=0 ){
correto++;
}else{
break;
}
}
for(i=3;i<=6;i++){
j=isalnum(placa[i]);
if(j!=0){
correto++;
}else{
break;
}
}
if(correto==7){
printf("A placa %s eh valida!!\n", placa);
}
else{
printf("A placa eh invalida\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment