Why do not you want to increase?

-3

I want to increment the cont variable if the character vector is not null, understand? But nothing happens. Because?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void main(){

int i;
char testeNome[190];
int cont;
printf("Digite seu primeiro nome: ");
scanf("%s",testeNome);


while(testeNome != "
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void main(){

int i;
char testeNome[190];
int cont;
printf("Digite seu primeiro nome: ");
scanf("%s",testeNome);


while(testeNome != "%pre%"){

    cont++; 
    }

printf("%d",cont);
}
"){ cont++; } printf("%d",cont); }
    
asked by anonymous 21.04.2016 / 01:35

1 answer

4

Friend, follow the code working:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main(){

int i = 0;
char testeNome[190];
int cont = 0;
printf("Digite seu primeiro nome: ");
scanf("%s",testeNome);

while(testeNome[i] != '
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main(){

int i = 0;
char testeNome[190];
int cont = 0;
printf("Digite seu primeiro nome: ");
scanf("%s",testeNome);

while(testeNome[i] != '%pre%'){
    cont++;
    i++;
}

printf("%d",cont);
}
'){ cont++; i++; } printf("%d",cont); }

You forgot to use the variable i to treat the characters of the string, using it in testName and incrementing the i within the loop. Also, since \ 0 is a character, we need to indicate it in single quotation marks.

Aah, and it's always good to start variables (cont and i) with 0 to avoid having any value from a previous run.

I hope I have helped

    
21.04.2016 / 01:49