Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem

problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T toxcct

    if you look at the fgets()[^] function behavior, it waits for a "maximum characters to read" parameter ; so i believe that your problem comes from the length of your buffer (if you read a line which is wider that your buffer, it will be truncated)


    TOXCCT >>> GEII power

    [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

    V Offline
    V Offline
    V_shr
    wrote on last edited by
    #3

    no , i put n=1000 and ... is less than 100 characters . and also when i read : dsalgujbslgkusdhglidsufhgllkufg it is true but <#if dsgubsldfjgblfdgbldfgb #> is false !!!!!!!!!!!!!!!!!!!!!!!!! i dont know why fgets act like this .

    T 1 Reply Last reply
    0
    • V V_shr

      no , i put n=1000 and ... is less than 100 characters . and also when i read : dsalgujbslgkusdhglidsufhgllkufg it is true but <#if dsgubsldfjgblfdgbldfgb #> is false !!!!!!!!!!!!!!!!!!!!!!!!! i dont know why fgets act like this .

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #4

      use you debugger to compare the string you read and what is actually filled in your buffer. btw, do you have any \n, spaces or escape characters in the string read ?


      TOXCCT >>> GEII power

      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

      V 1 Reply Last reply
      0
      • T toxcct

        use you debugger to compare the string you read and what is actually filled in your buffer. btw, do you have any \n, spaces or escape characters in the string read ?


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        V Offline
        V Offline
        V_shr
        wrote on last edited by
        #5

        I haven't any '\n' , space and scape . this is what happens : the file is: <#if...#> hello the code is: --------------- debugger shows : char string[1000]=""; // string = "" > fgets("adress",1000,input); // string = "<#if.." fgets("adress",1000,input); // string = "<#if.."

        V D 2 Replies Last reply
        0
        • V V_shr

          I haven't any '\n' , space and scape . this is what happens : the file is: <#if...#> hello the code is: --------------- debugger shows : char string[1000]=""; // string = "" > fgets("adress",1000,input); // string = "<#if.." fgets("adress",1000,input); // string = "<#if.."

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #6

          My be fgets("adress",1000,input) must be replaced with fgets(string,1000,input)?

          V 1 Reply Last reply
          0
          • V Viorel

            My be fgets("adress",1000,input) must be replaced with fgets(string,1000,input)?

            V Offline
            V Offline
            V_shr
            wrote on last edited by
            #7

            AH ofcourse it was a misprint , it is true in my code . -- modified at 8:54 Tuesday 6th June, 2006

            C V 2 Replies Last reply
            0
            • V V_shr

              AH ofcourse it was a misprint , it is true in my code . -- modified at 8:54 Tuesday 6th June, 2006

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #8

              Can you post your code ? (With the opening of the file also)


              Cédric Moonen Software developer
              Charting control

              V 1 Reply Last reply
              0
              • V V_shr

                AH ofcourse it was a misprint , it is true in my code . -- modified at 8:54 Tuesday 6th June, 2006

                V Offline
                V Offline
                Viorel
                wrote on last edited by
                #9

                I think you should provide the entire fragment between the line where you open the file (fopen) and close it (fclose), and may be a precise content of input file. Perhaps, someone will figure out the problem. If your program is too big, try to remove (comment) some fragments, keeping file-processing only. Thus you should be able to reproduce the problem for a smaller program.

                1 Reply Last reply
                0
                • V V_shr

                  I haven't any '\n' , space and scape . this is what happens : the file is: <#if...#> hello the code is: --------------- debugger shows : char string[1000]=""; // string = "" > fgets("adress",1000,input); // string = "<#if.." fgets("adress",1000,input); // string = "<#if.."

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  How are you verifying the contents of string?


                  "The largest fire starts but with the smallest spark." - David Crow

                  "Judge not by the eye but by the heart." - Native American Proverb

                  1 Reply Last reply
                  0
                  • C Cedric Moonen

                    Can you post your code ? (With the opening of the file also)


                    Cédric Moonen Software developer
                    Charting control

                    V Offline
                    V Offline
                    V_shr
                    wrote on last edited by
                    #11

                    how can I post the files to you ?

                    C 1 Reply Last reply
                    0
                    • V V_shr

                      how can I post the files to you ?

                      C Offline
                      C Offline
                      Cedric Moonen
                      wrote on last edited by
                      #12

                      Just post the relevant information here (the code snippet that opens and read from the files with the variables that are used). Please use the code tags (above the emoticons)


                      Cédric Moonen Software developer
                      Charting control

                      V 1 Reply Last reply
                      0
                      • C Cedric Moonen

                        Just post the relevant information here (the code snippet that opens and read from the files with the variables that are used). Please use the code tags (above the emoticons)


                        Cédric Moonen Software developer
                        Charting control

                        V Offline
                        V Offline
                        V_shr
                        wrote on last edited by
                        #13

                        code is :

                        int main()
                        {
                        char khat[1000];
                        clrscr();
                        int i;
                        for(i=0;i<1000;i++) {khat[i]='\0'; if(i<100)counter[i]=0;}
                        FILE *f;
                        f=fopen("falle//in2.htm","r");
                        for(i=1;i<1000;i++)
                        {
                        fgets(khat,1000,f);
                        // here you can see the khat string
                        printf("%s\n",khat);
                        if(strcmp(khat,"")==0) break;
                        }
                        fclose(f);
                        char ch=getch();
                        if(ch==27) return 0;
                        return 0;
                        }

                        and file is :

                        <#if( 1+2^3 < 2*(2+3)+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1 )#>
                        correct
                        yes , it is correct
                        <#fi#>
                        incorect
                        <#loop 4#>
                        this is in the loop
                        and number is :
                        <#i#>
                        <#do#>

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups