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

  • Home
  • SEARCH
  • 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 8013581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:40:10+00:00 2026-06-04T19:40:10+00:00

Hello everybody, I’m a newbie and I’m doing a code that the principal aim

  • 0

Hello everybody,
I’m a newbie and I’m doing a code that the principal aim is to print a number if two strings are equal. First string is obtained from a file and the second one is the string to be compared with.

The code:

int main()
{
char *string[2];
FILE *stream;
stream = fopen("REL","r");
if( (stream = fopen("REL","r")) == NULL)
{  
    printf("Can't open %s\n","REL");
    exit(1);
}
for(int i=0;i<92;i++)
{
    fscanf(stream,"%s",&string);
    if( strcmp("20", *string) == 0 )
    {
        printf("%d",20);
    }
}
fclose(stream);
}

and… when I tested on shell, it promp to me:

~/CM$ ./file2 
Segmentation fault (core dumped)

I might be doing a silly mistake. But, as a newbie, I cannot figure out whats is going wrong with the script.

  • 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-06-04T19:40:11+00:00Added an answer on June 4, 2026 at 7:40 pm

    string is an unitialised array of 2 char*. The fscanf is attempting to write to memory where is should not. Declare string as an array of char:

    char string[256];
    

    and:

    fscanf(stream, "%255s", string); /* Limit number of
                                        chars read to prevent buffer overrun. */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everybody, I have a small code in PHP that I would like to
Hello everybody I have a problem with exception. The following code block do this
Hello everybody let me give you the background first: I'm working on a project
Note: Using Monotouch and doing all the UI Programatically. Hello everybody, I have a
Hello, everybody. We are developing an iPhone app which supported by a server-side that
So, hello everybody. I've made two test programs for creating a own control. One
Hello Everybody! I got the following error, while trying to test a code for
Hello dearest community. I have trouble in the last two days, that I can't
Lets say I have some code: <?php echo Hello Everybody!; echo <br/> ; $var1
Hello everybody i have variable(widthPercent) where i store percent for example: 67.33% when i

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.