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:
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.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) ; }
Thanks



LinkBack URL
About LinkBacks


