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 8687675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:10:39+00:00 2026-06-12T23:10:39+00:00

I have this array: char *tags[100]; If I do this: tags[0]=something; It works (no

  • 0

I have this array:

char *tags[100];

If I do this:

tags[0]="something";

It works (no errors at least). However, the very same code in a for loop doesn’t.

int j=0;       
for(j; j<100; ++j)
{
    tags[j]="something";
}

It says “Segmentation fault”. What is this?

UPDATE: Whole code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void append(char* s, char c)
{
        int len = strlen(s);
        s[len] = c;
        s[len+1] = '\0';
}


int main()
{
   int istag;
   FILE *fopen(), *fp;
   int i;
   fp = fopen("oldal.html","r");
   i= getc(fp) ;
   char* szo;

   int index=0;
   char *tags[100]; 

int j=0;       
for(j; j<100; ++j)
{
    tags[j]="something";
}


   while (i!= EOF)
   {            

        i = getc(fp);
        char c=i;

        if(c=='<')
        {
            istag=1;
        }
        if(c=='>')
        {
            istag=0;
            index++;
            //printf("tag vege: %s %d",tags[index],index);


        }

        if(istag)
        {

            //append(tags[index],'a');
        }

        append(szo,c);


   }

   //printf("%s",szo);
   fclose(fp);

   return 0;
}
  • 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-12T23:10:40+00:00Added an answer on June 12, 2026 at 11:10 pm

    Your code calls your append() function to append data to szo, but szo was never initialized and contains whatever value happened to be on the stack where it is declared.

    Who knows where it is writing to. This is almost certainly the cause of the problem.

    Initialize szo by pointing it to a character buffer of sufficient size. Remember to make it big enough to hold even the data and terminators that are appended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: void PrintMainParameters(int n, char* array[]) { int i = 0;
i have an array of type char char *arg[100] this array its reading the
I have this code : #define N 100 //starting size of the array int
I have this code: int indexOf(const char *array[], char *e) { printf(inside: %d\n,(int)sizeof(array)); /*
I have an array that is like this: unsigned char array[] = {'\xc0', '\x3f',
I have a C-array that looks like this: char hexc[] = { 0x41, 0x80,
I have an array of char * initialized like this: char *keys[16]; //16 elements,
In my code, I have char array and here it is: char pIPAddress[20]; And
I have a C code that creates an array of char pointers as the
I have this code: int main() { char ch[15]; cout<<strlen(ch)<<endl; //7 cout<<sizeof(ch)<<endl; //15 return

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.