This question already has an answer here:
- Single quotes vs. double quotes in C 11 answers
I was creating a simple program to count the words and vowels of a string, and when I try to use double quotes inside of a 'for' or an 'if' statement it gives an erro. But when I change it for a single quote it works pretty good.
I thought they were the same thing, so what is the difference between them and why I cannot use double quotes inside of a statement or single quote inside a 'printf' function?
PS: I'm using code blocks as my IDE.
Here is my code, so you can see an example:
#include <stdio.h>
#include <conio.h>
int main(void){
// Declaracao de Variaveis
int cont_p = 0, cont_v = 0, i;
char frase[1000];
// Leitura de Dados
printf("Digite a frase:\n");
gets(frase);
// Logica e Contagemm
for (i=0; frase[i]!='\0';i++){
if(frase[i] == ' '){
cont_p = cont_p +1;
}else if ((frase[i] == 'a') || (frase[i] == 'A')) {
cont_v = cont_v + 1;
}else if ((frase[i] == 'e') || (frase[i] == 'E')) {
cont_v = cont_v + 1;
}else if ((frase[i] == 'i') || (frase[i] == 'I')) {
cont_v = cont_v + 1;
}else if ((frase[i] == 'o') || (frase[i] == 'O')) {
cont_v = cont_v + 1;
}else if ((frase[i] == 'u') || (frase[i] == 'U')) {
cont_v = cont_v + 1;
}
}
cont_p++;
// Exibindo o Resultado
printf("\n\nNumero de PALAVRAS: %d\n", cont_p);
printf("Numero de VOGAIS: %d\n\n\n", cont_v);
printf("Programa Finalizado!\n");
getch();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire