How to have a cycle range up to \ n and up to \ 0

1

In a validation function that passes all the tests will return 1, and if it enters one of the conditions it will give return to 0.

I want to loop through the line break, so I'm using the range:

for(int i=0;dados[4][i]!='\n';i++){
    if(!isdigit(dados[4][i])){
         return 0;
    }
 }

The file has already been split and saved in a dados[4][20] array, with lines of the genre

 4 ; Visitante ; 3 ; 0 ; 3 \n
 4 ; Visitante ; 3 ; 0 ; 3 \n
 4 ; Visitante ; 3 ; 0 ; 3 
for(int i=0;dados[4][i]!='\n';i++){
    if(!isdigit(dados[4][i])){
         return 0;
    }
 }

However, in the last line of the file, there is no longer a line break but a %code% , so it will not allow us to validate the last line

    
asked by anonymous 13.06.2018 / 16:43

2 answers

2

That's a lot better:

for (int i = 0; dados[4][i] != '\n' && dados[4][i] != '
for (int i = 0; dados[4][i] != '\n' && dados[4][i] != '%pre%'; i++) if (!isdigit(dados[4][i])) return 0;
'; i++) if (!isdigit(dados[4][i])) return 0;
    
13.06.2018 / 17:18
0

I have been able to solve the problem by adding a condition inside the for:

 for(int i=0;dados[4][i]!='\n';i++){
    if(dados[4][i]=='
 for(int i=0;dados[4][i]!='\n';i++){
    if(dados[4][i]=='%pre%'){
        break;
    }
    if(!isdigit(dados[4][i])){
         return 0;
    }
 }
'){ break; } if(!isdigit(dados[4][i])){ return 0; } }
    
13.06.2018 / 17:00