Thread: pointer problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    35

    Unhappy pointer problem

    I am trying to read a file into a single array. For some reason, I cannot get a pointer, s1, to point to the beginning of the array. Here is my code:

    Code:
    #include<stdio.h>
    #include<string.h>
    
    #define BUFFER_SIZE 30
    #define BIG_BUFFER 1024
    #define TRUNCATE_BUF 100
    
    int main(void)
    {
       int i = 0 ;
       
       char file_string_buf[BIG_BUFFER] ;
       char *s1 = file_string_buf ;
       char *s2 = "cpu" ;
       char truncate_string_buf[TRUNCATE_BUF] ;
    
       FILE * infile ;
       FILE * outfile ;
    
       infile  = fopen("/proc/cpuinfo", "r" );
       outfile = fopen("cpuinfo.txt", "w" );
    
       fprintf( outfile, "\n" ) ;
       /*s1 = file_string_buf ;*/  
    
       while (fgets( file_string_buf, BIG_BUFFER, infile) != NULL ) 
             printf("%s", s1 ) ; 
    
        /*    fprintf(outfile, "%s", file_string_buf ) ;*/
          
          s1 = file_string_buf ;  /*
       
       printf("s2 = %s\n", s2) ;
       printf("s1 = %s\n", s1 ) ;
     
       printf("\ncpuinfo.txt created\n" ) ;
    
       printf("\n%s\n", strstr(s1,s2)) ;
    
    
       fclose(infile) ;
       fclose(outfile) ;
    
       return(0) ;
    
    }
    As you can see, the while loop pulls the file info into a buffer called file_string_buf . I also assign s1 to point to file_string_buf at the beginning and after the file is read in. What's the problem??? Do I need to reset the file_string_buf pointer??? I don't know.


    Thanks
    Last edited by DMaxJ; 06-11-2003 at 09:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 08:53 PM
  2. Another pointer problem
    By mikahell in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2006, 07:37 PM
  3. Pointer problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2006, 10:21 AM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM