Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3670632
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:23:21+00:00 2026-05-19T02:23:21+00:00

#include <stdio.h> #include<stdio.h> #include <ctype.h> /** * Display the contents of a stream as

  • 0
#include <stdio.h>
#include<stdio.h>  
#include <ctype.h>

  /**
   * Display the contents of a stream as hexadecimal bytes and text.
   * @param file pointer to a binary stream
   * @return the number of bytes in the file read
   */
  size_t hexdump(FILE *file,FILE *fp,FILE *fp1)
  {
      unsigned char data[16];
      size_t i, j, size, count = 0;
      /*
       * Heading
       */
      fputs(" ", stdout); /* skip address area */
      for ( i = 0; i < sizeof data / sizeof *data; ++i )
      {
          printf("+%lX ", (long unsigned)i);
      }
      puts("Text");
      /*
       * Body
       */
      do {
          /* Read some data. */
          size = fread(data, sizeof *data, sizeof data / sizeof *data, file);
          if ( size )
          {
              /* Print the base address. */
              printf("%08lX ", (long unsigned)count);
              fprintf(fp,"%08lX",(long unsigned)count);  
              count += size; /* adjust the base address */
              /* Print the characters' hex values. */
              for ( i = 0; i < size; ++i )
              {
                  printf("%02X ", data[i]);
                  fprintf(fp1,"%02X",data[i]);
              }
              /* Pad the hex values area if necessary. */
              for ( ++i; i <= sizeof data / sizeof *data; ++i )
              {
                  fputs(" ", stdout);
              }
              /* Print the characters (use '.' for non-printing characters). */
              /*      for ( j = 0; j < size; j++ )
                      {
                      putchar(isprint(data[j]) ? data[j] : '.');
                      }*/
              putchar('\n');
          }
      } while ( size == sizeof data / sizeof *data ); /* Break on partial count. */
      return count;
  }

  int main(void)
  {
      char filename[20] ;/* may not work on everywhere */
      char filename1[20];
      char filename2[20];
      printf("enter the filename\n");
      scanf("%s",filename); 
      printf("enter the filename to store address\n");
      scanf("%s",filename1);
      printf("enter the filename to store data\n");
      scanf("%s",filename2); 
      FILE *file = fopen(filename, "rb");
      FILE *fp= fopen(filename1,"wb");
      FILE *fp1=fopen(filename2,"rb");
      if ( file != NULL )
      {
          printf("%lu bytes\n", (long unsigned)hexdump(file,fp,fp1));
          fclose(file);
          fclose(fp);
          fclose(fp1);  
      }
      else
      {
          perror(filename);
      }
      return 0;
  }

When executing the code above, I got a segmentation fault. Here’s the output:

+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F Text
Segmentation fault

What could be reason for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:23:21+00:00Added an answer on May 19, 2026 at 2:23 am
    FILE *fp1=fopen(filename2,"rb");
    

    You open fp1 for reading. Yet you write to it. Change it to

    FILE *fp1=fopen(filename2,"wb");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> #include<ctype.h> int main() { char a,b; FILE *fp; fp=fopen(lext.txt,w); fprintf(fp,PLUS); return 0; }
#include <stdio.h> #include <ctype.h> void readFile(FILE *file); void count (FILE *file, int *alpha, int
My code #include <stdio.h> #include <stdlib.h> #include <ctype.h> void getData(short int *number, char *string)
#include<stdio.h> #include<ctype.h> #include<string.h> /* this is a lexer which recognizes constants , variables ,symbols,
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
#include<stdio.h> #include<ctype.h> #include<string.h> int main() { int i=0,j,k,lines_count[2]={1,1},operand_count[2]={0},operator_count[2]={0},uoperator_count[2]={0},control_count[2]={0,0},cl[13]={0},variable_dec[2]={0,0},l,p[2]={0},ct,variable_used[2]={0,0},constant_count[2],s[2]={0},t[2]={0}; char a,b[100],c[100]; char d[100]={0}; j=30; FILE
#include <stdio.h> #include <ctype.h> /*header for standard tolower function*/ #define STRING_LEN 500 char *
#include <stdio.h> #include <ctype.h> int isPalindrome( char *str, int length ) { if (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.