remove entry from text file [NOT A HOMEWORK]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roman Mashak

    remove entry from text file [NOT A HOMEWORK]

    Hello, All!

    I implemented simple program to eliminate entry from the file having the
    following structure (actually it's config file of 'named' DNS package for
    those who care and know):

    options {
    directory "/var/named";
    listen-on { 192.168.11.22; 127.0.0.1; };
    forwarders { 168.126.63.1; };
    pid-file "/var/run/named.pid";
    };

    controls {
    unix "/var/run/ndc" perm 0600 owner 0 group 0;
    };

    zone "." {
    type hint;
    file "root.cache ";
    };

    zone "localhost" {
    type master;
    file "localhost" ;
    };

    zone "my.local" {
    type master;
    file "my.local";
    allow-update { 127.0.0.1; 192.168.11.0/24; };
    };
    ....

    I bother only about "zone" entries and the goal of code to remove them only.
    Here is the source code I'm done with. I'd like to hear reasonable criticism
    and useful advices :-) on optimization, bugs etc.

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

    #define BUFSIZE 100

    int main(int argc, char **argv)
    {
    FILE *f; /* original */
    FILE *fn; /* new */
    char buf[BUFSIZE] = { 0 };
    register char *idx;
    char sidx[BUFSIZE];
    int found = 0; /* set if zone found */
    int i = 0;

    if (argc != 3) {
    fprintf(stderr, "Usage: %s <zonename> <configfile>\n" , *argv);
    return (0);
    }

    printf("%s %s\n", argv[1], argv[2]);

    /* open original */
    if ( (f = fopen(argv[2], "r")) == NULL )
    return -1;

    if ( (fn = fopen("named.co nf.tmp", "w+")) == NULL )
    return -1;

    while ( !feof(f) ) {
    fgets(buf, BUFSIZE, f);

    /* skip leading spaces */
    for (idx = buf; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
    ;

    /* look for 'zone' token */
    if ( strncasecmp(idx , "zone ", sizeof("zone ") - 1) != 0 ) {
    if (!found) {
    fprintf(fn, buf);
    fflush(fn);
    }
    continue;
    }

    idx += sizeof("zone ") - 1;

    /* skip spaces inside of token */
    for (; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
    ;

    /* extract token from commas */
    if (*idx++ != '"')
    continue;

    /* put token into buffer to compare */
    while (*idx != '\0' && *idx != '"')
    sidx[i++] = *idx++;

    sidx[i] = '\0'; i = 0;
    if (strcasecmp(sid x, argv[1]) != 0) {
    found = 0;
    fprintf(fn, buf);
    fflush(fn);
    }
    else
    found = 1;
    }

    fclose(f);
    fclose(fn);

    return 0;
    }

    Thank you in advance.

    With best regards, Roman Mashak. E-mail: mrv@tusur.ru


  • tmp123

    #2
    Re: remove entry from text file [NOT A HOMEWORK]


    Roman Mashak wrote:[color=blue]
    > Hello, All!
    >
    > I implemented simple program to eliminate entry from the file having the
    > following structure (actually it's config file of 'named' DNS package for
    > those who care and know):
    >
    > options {
    > directory "/var/named";
    > listen-on { 192.168.11.22; 127.0.0.1; };
    > forwarders { 168.126.63.1; };
    > pid-file "/var/run/named.pid";
    > };
    >
    > controls {
    > unix "/var/run/ndc" perm 0600 owner 0 group 0;
    > };
    >
    > zone "." {
    > type hint;
    > file "root.cache ";
    > };
    >
    > zone "localhost" {
    > type master;
    > file "localhost" ;
    > };
    >
    > zone "my.local" {
    > type master;
    > file "my.local";
    > allow-update { 127.0.0.1; 192.168.11.0/24; };
    > };
    > ...
    >
    > I bother only about "zone" entries and the goal of code to remove them only.
    > Here is the source code I'm done with. I'd like to hear reasonable criticism
    > and useful advices :-) on optimization, bugs etc.
    >
    > #include <stdio.h>
    > #include <string.h>
    > #include <strings.h>
    >
    > #define BUFSIZE 100
    >
    > int main(int argc, char **argv)
    > {
    > FILE *f; /* original */
    > FILE *fn; /* new */
    > char buf[BUFSIZE] = { 0 };
    > register char *idx;
    > char sidx[BUFSIZE];
    > int found = 0; /* set if zone found */
    > int i = 0;
    >
    > if (argc != 3) {
    > fprintf(stderr, "Usage: %s <zonename> <configfile>\n" , *argv);
    > return (0);
    > }
    >
    > printf("%s %s\n", argv[1], argv[2]);
    >
    > /* open original */
    > if ( (f = fopen(argv[2], "r")) == NULL )
    > return -1;
    >
    > if ( (fn = fopen("named.co nf.tmp", "w+")) == NULL )
    > return -1;
    >
    > while ( !feof(f) ) {
    > fgets(buf, BUFSIZE, f);
    >
    > /* skip leading spaces */
    > for (idx = buf; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
    > ;
    >
    > /* look for 'zone' token */
    > if ( strncasecmp(idx , "zone ", sizeof("zone ") - 1) != 0 ) {
    > if (!found) {
    > fprintf(fn, buf);
    > fflush(fn);
    > }
    > continue;
    > }
    >
    > idx += sizeof("zone ") - 1;
    >
    > /* skip spaces inside of token */
    > for (; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
    > ;
    >
    > /* extract token from commas */
    > if (*idx++ != '"')
    > continue;
    >
    > /* put token into buffer to compare */
    > while (*idx != '\0' && *idx != '"')
    > sidx[i++] = *idx++;
    >
    > sidx[i] = '\0'; i = 0;
    > if (strcasecmp(sid x, argv[1]) != 0) {
    > found = 0;
    > fprintf(fn, buf);
    > fflush(fn);
    > }
    > else
    > found = 1;
    > }
    >
    > fclose(f);
    > fclose(fn);
    >
    > return 0;
    > }
    >
    > Thank you in advance.
    >
    > With best regards, Roman Mashak. E-mail: mrv@tusur.ru[/color]

    Look for references about "lex" C source generator (or even "yacc" if
    you have more complex requirements like this one)

    Comment

    • Sirius Black

      #3
      Re: remove entry from text file [NOT A HOMEWORK]

      Roman Mashak wrote:[color=blue]
      > Hello, All!
      >
      > I implemented simple program to eliminate entry from the file having the
      > following structure (actually it's config file of 'named' DNS package for
      > those who care and know):
      > <snip>
      > if ( (fn = fopen("named.co nf.tmp", "w+")) == NULL )
      > return -1;
      >[/color]

      Here, because of opening the file for writing in present directory, it
      will restrict the directory from which a user can run your program. If a
      user does n't have write permission for the present directory, then he
      will have to change the directory and run your program.

      Probably you should have explained algorithm used in your program in
      short paragraph.

      Comment

      • boa

        #4
        Re: remove entry from text file [NOT A HOMEWORK]

        Roman Mashak wrote:[color=blue]
        > Hello, All!
        >
        > I implemented simple program to eliminate entry from the file having the
        > following structure (actually it's config file of 'named' DNS package for
        > those who care and know):
        >
        > options {
        > directory "/var/named";
        > listen-on { 192.168.11.22; 127.0.0.1; };
        > forwarders { 168.126.63.1; };
        > pid-file "/var/run/named.pid";
        > };
        >
        > controls {
        > unix "/var/run/ndc" perm 0600 owner 0 group 0;
        > };
        >
        > zone "." {
        > type hint;
        > file "root.cache ";
        > };
        >
        > zone "localhost" {
        > type master;
        > file "localhost" ;
        > };
        >
        > zone "my.local" {
        > type master;
        > file "my.local";
        > allow-update { 127.0.0.1; 192.168.11.0/24; };
        > };
        > ...
        >
        > I bother only about "zone" entries and the goal of code to remove them only.
        > Here is the source code I'm done with. I'd like to hear reasonable criticism
        > and useful advices :-) on optimization, bugs etc.
        >
        > #include <stdio.h>
        > #include <string.h>
        > #include <strings.h>[/color]

        strings.h?
        [color=blue]
        >
        > #define BUFSIZE 100
        >
        > int main(int argc, char **argv)
        > {
        > FILE *f; /* original */
        > FILE *fn; /* new */
        > char buf[BUFSIZE] = { 0 };
        > register char *idx;
        > char sidx[BUFSIZE];
        > int found = 0; /* set if zone found */
        > int i = 0;
        >
        > if (argc != 3) {
        > fprintf(stderr, "Usage: %s <zonename> <configfile>\n" , *argv);
        > return (0);[/color]

        Maybe return EXIT_FAILURE to indicate an error?
        [color=blue]
        > }
        >
        > printf("%s %s\n", argv[1], argv[2]);
        >
        > /* open original */
        > if ( (f = fopen(argv[2], "r")) == NULL )
        > return -1;[/color]

        Again, EXIT_FAILURE.
        [color=blue]
        >
        > if ( (fn = fopen("named.co nf.tmp", "w+")) == NULL )[/color]

        How about using tmpnam() instead?
        [color=blue]
        > return -1;
        >
        > while ( !feof(f) ) {
        > fgets(buf, BUFSIZE, f);[/color]

        See http://c-faq.com/stdio/feof.html
        [color=blue]
        >
        > /* skip leading spaces */
        > for (idx = buf; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
        > ;
        >
        > /* look for 'zone' token */
        > if ( strncasecmp(idx , "zone ", sizeof("zone ") - 1) != 0 ) {[/color]

        strlen("zone"), not sizeof().
        [color=blue]
        > if (!found) {
        > fprintf(fn, buf);
        > fflush(fn);[/color]

        Why do you need to call fflush()?

        [color=blue]
        > }
        > continue;
        > }
        >
        > idx += sizeof("zone ") - 1;
        >
        > /* skip spaces inside of token */
        > for (; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
        > ;[/color]

        How about a function that strips the white space?

        [color=blue]
        >
        > /* extract token from commas */
        > if (*idx++ != '"')
        > continue;
        >
        > /* put token into buffer to compare */
        > while (*idx != '\0' && *idx != '"')
        > sidx[i++] = *idx++;
        >
        > sidx[i] = '\0'; i = 0;
        > if (strcasecmp(sid x, argv[1]) != 0) {
        > found = 0;
        > fprintf(fn, buf);
        > fflush(fn);
        > }
        > else
        > found = 1;
        > }
        >
        > fclose(f);
        > fclose(fn);
        >
        > return 0;
        > }[/color]

        That's a start, HTH.

        Boa

        Comment

        • Micah Cowan

          #5
          Re: remove entry from text file [NOT A HOMEWORK]

          "Roman Mashak" <mrv@tusur.ru > writes:
          [color=blue]
          > Hello, All!
          >
          > I implemented simple program to eliminate entry from the file having the
          > following structure (actually it's config file of 'named' DNS package for
          > those who care and know):[/color]

          <snip>
          [color=blue]
          > zone "." {
          > type hint;
          > file "root.cache ";
          > };
          >
          > zone "localhost" {
          > type master;
          > file "localhost" ;
          > };
          >
          > zone "my.local" {
          > type master;
          > file "my.local";
          > allow-update { 127.0.0.1; 192.168.11.0/24; };
          > };[/color]

          <snip> (here's the code:)
          [color=blue]
          > #include <stdio.h>
          > #include <string.h>
          > #include <strings.h>[/color]

          The last of these is not Standard C; see my discussion later.
          [color=blue]
          >
          > #define BUFSIZE 100
          >
          > int main(int argc, char **argv)
          > {
          > FILE *f; /* original */
          > FILE *fn; /* new */
          > char buf[BUFSIZE] = { 0 };
          > register char *idx;
          > char sidx[BUFSIZE];
          > int found = 0; /* set if zone found */
          > int i = 0;
          >
          > if (argc != 3) {
          > fprintf(stderr, "Usage: %s <zonename> <configfile>\n" , *argv);
          > return (0);
          > }
          >
          > printf("%s %s\n", argv[1], argv[2]);
          >
          > /* open original */
          > if ( (f = fopen(argv[2], "r")) == NULL )
          > return -1;[/color]

          A return of -1 will have an implementation-defined meaning... slightly
          better would be to #include <stdlib.h> and return EXIT_FAILURE; which
          is guaranteed to have the obvious meaning on any current or future
          implementation.

          Also, it would really pay to emit some sort of message here. You'll
          really thank yourself when you accidentally open a non-existant file,
          or non-readable.... etc.
          [color=blue]
          > if ( (fn = fopen("named.co nf.tmp", "w+")) == NULL )
          > return -1;
          >
          > while ( !feof(f) ) {
          > fgets(buf, BUFSIZE, f);
          >
          > /* skip leading spaces */
          > for (idx = buf; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
          > ;
          >
          > /* look for 'zone' token */
          > if ( strncasecmp(idx , "zone ", sizeof("zone ") - 1) != 0 ) {[/color]

          Whenever I find myself having to use the exact same string literal
          twice like this, it's time to farm it out. Using something like:

          const char zone_token[] = "zone ";
          ...
          if (strncasecmp(id x, zone_token, (sizeof zone_token)-1) != 0)

          saves you from the problem of accidental typos. If the number of
          characters between the two of those were to accidentally get out of
          sync, it'd be a bug. And even though you have them exactly right now,
          you might later need to change the code to use a different literal,
          and accidentally change only one.

          BTW, strncasecmp() is not a Standard C function (it's POSIX, which is
          not on-topic here). The residents on this newsgroup insist that you do
          not post code containing functions that are (a) not Standard C
          functions and (b) not defined in the provided code. For the sake of
          example code on this newsgroup, the easiest way for you to avoid
          difficulties is probably to use strncmp() instead. Or, define your own
          implementation of strncasecmp().. .
          [color=blue]
          > if (!found) {
          > fprintf(fn, buf);
          > fflush(fn);
          > }
          > continue;
          > }
          >
          > idx += sizeof("zone ") - 1;[/color]

          If you decide to follow my advice, this would become:

          idx += (sizeof zone_array) - 1;

          Actually, my own preference has been to define a macro such as:

          #define ARY_STRLEN(a) (sizeof(a)-1)

          which leads to a slightly better expression, in terms of
          self-documentation:

          idx += ARY_STRLEN(zone _array) - 1;
          [color=blue]
          > /* skip spaces inside of token */
          > for (; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
          > ;[/color]

          This is the same thing as:

          idx += strspn(idx, " \t");
          [color=blue]
          >
          > /* extract token from commas */
          > if (*idx++ != '"')
          > continue;
          >
          > /* put token into buffer to compare */
          > while (*idx != '\0' && *idx != '"')
          > sidx[i++] = *idx++;
          >
          > sidx[i] = '\0'; i = 0;[/color]

          The second statement on the line above is easy to miss. I'd recommend
          giving each of these a separate line.
          [color=blue]
          > if (strcasecmp(sid x, argv[1]) != 0) {
          > found = 0;
          > fprintf(fn, buf);
          > fflush(fn);
          > }
          > else
          > found = 1;
          > }
          >
          > fclose(f);
          > fclose(fn);
          >
          > return 0;
          > }[/color]

          The last pair of fclose()s are not strictly necessary, if you're not
          going to check their return value. However, I'd recommend that you do
          check their return value, so you can emit an error message if fn
          didn't flush properly... actually, you should check the return code of
          your fflush() calls, too.

          I'll point out that the code above won't work properly if your config
          file contains lines longer than 100 characters.

          -Micah

          Comment

          • Micah Cowan

            #6
            Re: remove entry from text file [NOT A HOMEWORK]

            boa <boasema@gmail. com> writes:
            [color=blue]
            > Roman Mashak wrote:[color=green]
            > > /* skip leading spaces */
            > > for (idx = buf; *idx != '\0' && (*idx == ' ' || *idx == '\t'); idx++)
            > > ;
            > > /* look for 'zone' token */
            > > if ( strncasecmp(idx , "zone ", sizeof("zone ") - 1) != 0 ) {[/color]
            >
            > strlen("zone"), not sizeof().[/color]

            You mean, strlen("zone ") (with the space); and there's nothing wrong
            with sizeof: it's much more efficient.
            [color=blue][color=green]
            > > if (!found) {
            > > fprintf(fn, buf);
            > > fflush(fn);[/color]
            >
            > Why do you need to call fflush()?[/color]

            Could be useful if he's using another program to view the temporary
            file while it's being written (UNIX tail...).

            Slightly better might be to set line buffering on fn with setvbuf().

            -Micah

            Comment

            • Pedro Graca

              #7
              Re: remove entry from text file [NOT A HOMEWORK]

              Micah Cowan wrote:[color=blue]
              > boa <boasema@gmail. com> writes:
              >[color=green]
              >> Roman Mashak wrote:[color=darkred]
              >> > /* look for 'zone' token */
              >> > if ( strncasecmp(idx , "zone ", sizeof("zone ") - 1) != 0 ) {[/color]
              >>
              >> strlen("zone"), not sizeof().[/color]
              >
              > You mean, strlen("zone ") (with the space); and there's nothing wrong
              > with sizeof: it's much more efficient.[/color]

              Hmmmm ???

              What's the type of a literal string in code?
              I thought it was `const char *'



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

              int main(void) {
              int a, b, c, d, e, f;
              char * z1 = "forty two";
              char z2[] = "forty two";

              a = strlen("forty two");
              b = (int)sizeof("fo rty two");
              c = (int)sizeof(cha r*);
              d = (int)sizeof(con st char*);
              e = (int)sizeof z1;
              f = (int)sizeof z2; /* Ah! A match */
              printf("%d, %d, %d, %d, %d, %d\n",
              a, b, c, d, e, f);
              return 0;
              }


              No Micah, I wasn't doubting you (... well, maybe just a little)
              I stand corrected.

              --
              If you're posting through Google read <http://cfaj.freeshell. org/google>

              Comment

              • pete

                #8
                Re: remove entry from text file [NOT A HOMEWORK]

                Pedro Graca wrote:
                [color=blue]
                > What's the type of a literal string in code?[/color]

                An array of some number of char.
                No implict const qualifier,
                just trouble if you attempt to modify the object.

                --
                pete

                Comment

                • Keith Thompson

                  #9
                  Re: remove entry from text file [NOT A HOMEWORK]

                  pete <pfiland@mindsp ring.com> writes:[color=blue]
                  > Pedro Graca wrote:
                  >[color=green]
                  >> What's the type of a literal string in code?[/color]
                  >
                  > An array of some number of char.
                  > No implict const qualifier,
                  > just trouble if you attempt to modify the object.[/color]

                  "trouble" being undefined behavior.

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                  We must do something. This is something. Therefore, we must do this.

                  Comment

                  • Roman Mashak

                    #10
                    Re: remove entry from text file [NOT A HOMEWORK]

                    Hello, boa!
                    You wrote on Thu, 23 Feb 2006 20:16:14 +0100:

                    ??>> #include <strings.h>

                    b> strings.h?
                    I should've apologized for using of non-standard stuffs :)
                    ??>> #define BUFSIZE 100
                    ??>>
                    ??>> int main(int argc, char **argv)
                    ??>> if ( (fn = fopen("named.co nf.tmp", "w+")) == NULL )

                    b> How about using tmpnam() instead?
                    Manual of my system strongly recommends never to use this function cause of
                    being unsafe.
                    ??>> return -1;
                    ??>>
                    ??>> while ( !feof(f) ) {
                    ??>> fgets(buf, BUFSIZE, f);

                    b> See http://c-faq.com/stdio/feof.html
                    Yeas, that was the problem I run into: printing '\n' twice, BUT it happened
                    only if I removed entry from the middle of file, otherwise everything came
                    right.
                    Thanks for hint.

                    ??>> if (!found) {
                    ??>> fprintf(fn, buf);
                    ??>> fflush(fn);

                    b> Why do you need to call fflush()?
                    I view the result file in the next console via "tail -f" (I'm using linux
                    presently).
                    ??>> }
                    ??>> continue;
                    ??>> }
                    ??>>

                    With best regards, Roman Mashak. E-mail: mrv@tusur.ru


                    Comment

                    • David Holland

                      #11
                      Re: remove entry from text file [NOT A HOMEWORK]

                      On 2006-02-23, boa <boasema@gmail. com> wrote:[color=blue][color=green]
                      > > if ( (fn = fopen("named.co nf.tmp", "w+")) == NULL )[/color]
                      >
                      > How about using tmpnam() instead?[/color]

                      <OT>
                      tmpnam is insecure in Unix; he's right to avoid it.
                      </OT>

                      Now, for something on topic...
                      [color=blue][color=green]
                      > > if (!found) {
                      > > fprintf(fn, buf);[/color][/color]
                      ^^^
                      Don't do that. Ever.

                      If the input file happens to contain a '%' character, undefined
                      behavior ensues.
                      [color=blue][color=green]
                      > > /* extract token from commas */
                      > > if (*idx++ != '"')
                      > > continue;[/color][/color]

                      This branch loses the input line, which probably isn't what was
                      intended.

                      --
                      - David A. Holland
                      (the above address works if unscrambled but isn't checked often)

                      Comment

                      • S.Tobias

                        #12
                        Re: remove entry from text file [NOT A HOMEWORK]

                        pete <pfiland@mindsp ring.com> wrote:[color=blue]
                        > Pedro Graca wrote:
                        >[color=green]
                        >> What's the type of a literal string in code?[/color]
                        >
                        > An array of some number of char.[/color]
                        ....

                        I beleive so, but what is C&V for that?

                        --
                        Stan Tobias
                        mailx `echo siXtY@FamOuS.Be dBuG.pAlS.INVALID | sed s/[[:upper:]]//g`

                        Comment

                        • Roman Mashak

                          #13
                          Re: remove entry from text file [NOT A HOMEWORK]

                          Hello, Micah!
                          You wrote on Thu, 23 Feb 2006 23:07:14 GMT:

                          [skip]
                          thanks for giving me many pieces of advices.

                          ??>> /* extract token from commas */
                          ??>> if (*idx++ != '"')
                          ??>> continue;
                          ??>>
                          ??>> /* put token into buffer to compare */
                          ??>> while (*idx != '\0' && *idx != '"')
                          ??>> sidx[i++] = *idx++;
                          ??>>
                          ??>> sidx[i] = '\0'; i = 0;

                          MC> The second statement on the line above is easy to miss. I'd recommend
                          MC> giving each of these a separate line.
                          Is there any way in your opinion to somehow optimize this piece of code,
                          make it more elegant :-) may be in less statements...

                          ??>> if (strcasecmp(sid x, argv[1]) != 0) {
                          ??>> found = 0;
                          ??>> fprintf(fn, buf);
                          ??>> fflush(fn);
                          ??>> }
                          ??>> else
                          ??>> found = 1;
                          ??>> }
                          ??>>
                          ??>> fclose(f);
                          ??>> fclose(fn);
                          ??>>
                          ??>> return 0;
                          ??>> }

                          MC> The last pair of fclose()s are not strictly necessary, if you're not
                          What do you mean by that? OS should take care of unclosed descriptors by
                          yourself?
                          MC> going to check their return value. However, I'd recommend that you do
                          MC> check their return value, so you can emit an error message if fn
                          MC> didn't flush properly... actually, you should check the return code of
                          MC> your fflush() calls, too.

                          MC> I'll point out that the code above won't work properly if your config
                          MC> file contains lines longer than 100 characters.
                          That's correct, but I assume sane config file won't contain strings longer
                          than 100 characters ;-)

                          With best regards, Roman Mashak. E-mail: mrv@tusur.ru


                          Comment

                          • Roman Mashak

                            #14
                            Re: remove entry from text file [NOT A HOMEWORK]

                            Hello, David!
                            You wrote on Fri, 24 Feb 2006 00:30:00 +0000 (UTC):

                            ??>>> if (!found) {
                            ??>>> fprintf(fn, buf);
                            DH> ^^^
                            DH> Don't do that. Ever.

                            DH> If the input file happens to contain a '%' character, undefined
                            DH> behavior ensues.
                            Hm, I didn't find this issue in FAQ. What's the more robust and portable
                            method to put formatted output into file?
                            ??>>> /* extract token from commas */
                            ??>>> if (*idx++ != '"')
                            ??>>> continue;

                            DH> This branch loses the input line, which probably isn't what was
                            DH> intended.
                            Here it is supposed to put a pointer on to first occurence of ' " ' symbol
                            in the line.

                            With best regards, Roman Mashak. E-mail: mrv@tusur.ru


                            Comment

                            • Jordan Abel

                              #15
                              Re: remove entry from text file [NOT A HOMEWORK]

                              On 2006-02-24, Keith Thompson <kst-u@mib.org> wrote:[color=blue]
                              > pete <pfiland@mindsp ring.com> writes:[color=green]
                              >> Pedro Graca wrote:
                              >>[color=darkred]
                              >>> What's the type of a literal string in code?[/color]
                              >>
                              >> An array of some number of char.
                              >> No implict const qualifier,
                              >> just trouble if you attempt to modify the object.[/color]
                              >
                              > "trouble" being undefined behavior.[/color]

                              This seems like an annoying compromise - I think it should have been
                              const char - any implementation concerned with supporting old code could
                              have let it been a warning, or have a compiler switch to put it in a
                              non-conforming mode, perhaps one which would also allow the
                              modifications themselves.

                              Comment

                              Working...