Fscanf

This is a discussion on Fscanf within the C++ Programming forums, part of the General Programming Boards category; Hello, again. For some reason, compiling works fine. But when run, I get bugs with fscanf. Now this obviously can't ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    56

    Fscanf

    Hello, again. For some reason, compiling works fine. But when run, I get bugs with fscanf. Now this obviously can't be Windows's fault. So is there something in the code that is causing this bug? I can't seem to find it.

    Code:
    // HTMLRandomizerDOS.cpp : Defines the entry point for the console application. 
     // 
      
     #include <ctype.h> 
     #include <stdio.h> 
     #include <string.h> 
      
     void stolower(char*a) 
     { 
          while (*a) 
          { 
               *a = tolower(*a); 
               a++; 
          } 
     } 
      
     int hrefreader(char *htmlpage,char* Links) 
     { 
          int numlinks = 0; 
          char *sp, *spe; 
          int irtn = 0; 
      
          if (sp = strstr(htmlpage, "href=")) 
               { 
                    sp += 6; 
                    spe = strstr (sp, "\""); 
                    strncpy (Links,sp,spe - sp); 
                    irtn  = 1; 
               } 
          return irtn; 
     } 
      
     int main(int argc, char* argv[]) 
     { 
          int numlinks; 
          FILE *nfile; 
          char htmlpage[2500]; 
          char Links[200][512]={102400*0}; 
          int i,j; 
          nfile = fopen((const char*)"Google.htm","r"); 
          i=0; 
          while (fscanf (nfile,"%s", htmlpage)!=EOF) 
          { 
               stolower (htmlpage); 
               j = hrefreader (htmlpage,(char*)Links[i]); 
               printf(" %s\n",Links[i]); 
               i = i + j; 
          } 
          for ( j=0; j<i;j++ ) { 
               printf(" %s\n",Links[j]); 
          } 
          return 0; 
     }
    Any help is appreciated.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    But when run, I get bugs with fscanf
    Can you describe the bugs ? What happens when you run it ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    2
    better solve the problem urself

    what is 'argc' and 'argv' doing? , where is google.htm? !!!!

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Code:
          char Links[200][512]={102400*0};
    What is ^^^this??? 102400 * 0 == 0 so why not just do like below
    Code:
          char Links[200][512]={0};

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    I just want to state right now that this is not my code. The person who wrote this code is trying to prove that Windows can't support/handle fscanf in "weird cases." The code itself has many problems. The bug message I get is Line 54 "stream != NULL" That should mean that something is wrong with the way he used fscanf.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    what compiler are you using? line 54 is the end of main() function. Maybe your compiler is complaining because the file was not closed before the function returns.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    56
    No, I apologize, I am using VC++ and it compiles just fine. The error message when debuging and just running the program in general, is the line 54 stuff.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf causes a SEGMENTATION FAULT
    By yougene in forum C Programming
    Replies: 15
    Last Post: 12-29-2008, 12:11 AM
  2. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 09:31 PM
  3. fscanf help
    By Axel in forum C Programming
    Replies: 13
    Last Post: 10-22-2006, 11:44 PM
  4. Using fscanf with a structure
    By daluu in forum C Programming
    Replies: 10
    Last Post: 10-11-2004, 02:32 PM
  5. fscanf on sun's
    By brif in forum C Programming
    Replies: 2
    Last Post: 04-14-2002, 02:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21