Tuesday, October 6, 2015

sscanf ler somente campos entre parentes nao incluindo os parenteses

#include <stdio.h>

int main() {
      char line[256], str[128], p1[128], p2[128];
     int n,m;
    n = 0; m=0;
        while (fgets(line, sizeof line, stdin)) {
                //n = sscanf(line, "%20[a-zA-Z0-9_] | %20[a-zA-Z0-9_] |%*[^(](%127[^)]", p1, p2, str);
                n = sscanf(line, "%20[a-zA-Z0-9_] | %20[a-zA-Z0-9_] | %[^\n]", p1, p2, str);
                //m = sscanf(line, "%*[^(](%127[^)]", str);
                printf("p1=%s\n",p1);
                printf("p2=%s\n",p2);
                printf("n=%d, m=%d, m+n=%d   -   |%s|\n",n,m,n+m, str);
        }

        return 0;
}

No comments:

Blog Archive