K
K
Konstantin Malyarov2016-04-24 19:29:28
C++ / C#
Konstantin Malyarov, 2016-04-24 19:29:28

Does the filter change the final result depending on how the list sequence is written?

Filter program. Reads a line, looks for an index, compares it - skips or writes to a file.

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

int main(){
    char city[80];
    char index[80];
    
    while(scanf("%79[^,],%79[^\n]", city, index) == 2){
        if(!strstr(index, "RU")){
            printf("%s,%s", city, index);
        }
    }
    return 0;
}

Sort list OPTION #1 :
Oslo,NO
Moscow,RU
London,EN
Minsk,BY
Beijing,CH
Krasnodar,RU

Result:
Oslo,NO
London,EN
Minsk,BY
Beijing,CH

List OPTION No. 2 (object index by which we sort, i.e. RU):
Moscow,RU
London,EN
Minsk,BY
Beijing,CH
Krasnodar,RU
Oslo,NO

Result:
//тут пустая строка
London,EN
Minsk,BY
Beijing,CH
Oslo,NO

Why did the list change (+1 line)? How to get rid of it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-04-24
@Rsa97

Your scanf does not capture the end of the string, as a result it is appended to the beginning of city on the next call.
Well, it's easier
grep -v ,RU <file>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question