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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:56:00+00:00 2026-05-22T11:56:00+00:00

This piece of code is part of a large source code but the bug

  • 0

This piece of code is part of a large source code but the bug is here.

int solve(int* unsolved_var)
{
        int i;
        for (i = 0; unsolved_var[i] != 0; i++)
        {
            int n;
            for (n = 1; n <= 9; n++)
            {
                 //if (!numInBox(unsolved_var[i], n)==1 || !numInLine()==1)

                 printf("%d  %d\n", n,  unsolved_var[i]);
         numInBox(unsolved_var[i], n);//ERROR OCCURS HERE
            }
        }
}

int numInBox(int space, int n)//space is always three digits long
{
   printf("this should print but doesnt(segmentation fault)");
   char unsolved_str[3];
   sprintf(unsolved_str, "%d", space);//converts int into char[]

   printf("%s",unsolved_str);//confirms

   int check[3] = {atoi(unsolved_str[0]), 0, atoi(unsolved_str[2])};//converts char[] to int[]

Complete Code…its long it runs fine thou. If you type in solve then ill throw you that error.

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

char grid[20][42];

void display()
{
        int j;
    int u;
    for (j = 0; j <= 19; j++)
    {
        for (u = 0; u <= 39; u++)
        {
            printf("%c",grid[j][u]);
        }
        printf("\n");
    }
    printf("\n");
}

int* unsolved()
{//2-18 4,8-36
int r;
int c;
   int size = 0;
   static int unsolved_var[81];
   unsolved_var[0] = 0;
   for (r = 2; r <= 18; r+=2)
   {
       for (c = 4; c <=36; c+=4)
       {
           if (grid[r][c] == ' ')
           {
           if (c <= 9)
               {
                   unsolved_var[size] = r/2*100 + c/4;
                   size++;
                   unsolved_var[size] = 0;//sets end of array
               }
               else
               {
                   unsolved_var[size] = r/2*100 + c/4;
                   size++;
                   unsolved_var[size] = 0;
               }
        // 100   1000    100   1000
            //2-0-4 2-0-10 10-0-4 10-0-10
           }
       }
   }
int p;
//for (p = 0; p <= size; p++){printf("%d", unsolved_var[p]);}
return unsolved_var;
}

int numInBox(int space, int n)
{
   char unsolved_str[3];
   sprintf(unsolved_str, "%d", space);

   printf("%s",unsolved_str);

   int check[3] = {atoi(unsolved_str[0]), 0, atoi(unsolved_str[2])};

}//***********************************************************************

static int x = 0;
int solve(int* unsolved_var)
{
   if (unsolved_var[0] == 0 || x == 10){return 0;}
   else
   {
        int i;
        for (i = 0; unsolved_var[i] != 0; i++)
        {
            int n;
            for (n = 1; n <= 9; n++)
            {
                 //if (!numInBox(unsolved_var[i], n)==1 || !numInLine()==1)

                 printf("%d  %d\n", n,  unsolved_var[i]);//
         numInBox(unsolved_var[i], n);
            }
        }
    x++;
   }
}

main()
{
//*****************************GRID******************************
//2 4 6 8 10 12 14 16 18
//3-5 7-9 11-13 15-17 19-21 23-25 27-29 31-33 35-37
        char top[] =   "\t  1   2   3   4   5   6   7   8   9  ";
    char line0[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field1[]="1\t|   |   |   |   |   |   |   |   |   |";
    char line1[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field2[]="2\t|   |   |   |   |   |   |   |   |   |";
    char line2[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field3[]="3\t|   |   |   |   |   |   |   |   |   |";
    char line3[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field4[]="4\t|   |   |   |   |   |   |   |   |   |";
    char line4[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field5[]="5\t|   |   |   |   |   |   |   |   |   |";
    char line5[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field6[]="6\t|   |   |   |   |   |   |   |   |   |";
    char line6[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field7[]="7\t|   |   |   |   |   |   |   |   |   |";
    char line7[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field8[]="8\t|   |   |   |   |   |   |   |   |   |";
    char line8[] = "\t+---+---+---+---+---+---+---+---+---+";
    char field9[]="9\t|   |   |   |   |   |   |   |   |   |";
    char line9[] = "\t+---+---+---+---+---+---+---+---+---+";

        int o;
        for (o = 0; o <= 39; o++)
        {
            grid[0][o] = top[o];
        grid[1][o] = line0[o];
        grid[2][o] = field1[o];
        grid[3][o] = line1[o];
        grid[4][o] = field2[o];
        grid[5][o] = line2[o];
        grid[6][o] = field3[o];
        grid[7][o] = line3[o];
        grid[8][o] = field4[o];
        grid[9][o] = line4[o];
        grid[10][o] = field5[o];
        grid[11][o] = line5[o];
        grid[12][o] = field6[o];
        grid[13][o] = line6[o];
        grid[14][o] = field7[o];
        grid[15][o] = line7[o];
        grid[16][o] = field8[o];
        grid[17][o] = line8[o];
        grid[18][o] = field9[o];
        grid[19][o] = line9[o];
        }
    display();
//****************************INPUT******************************
while(1)
{
  char input_raw[7];
  printf("Enter a Command\n");
  fgets(input_raw, 256, stdin);
  input_raw[strlen(input_raw)-1] = '\0';

if (strcmp(input_raw, "solve") == 0){solve(unsolved());}
else
{
  char *first = input_raw;
  char *second = input_raw; 
  char *third = input_raw;

  char *copy = input_raw;

  int flag = 1;
  while (*copy) 
  {
    if (*copy == ',') 
    {
      *copy = '\0'; 
      if (flag==0) {third = ++copy;}
      if (flag==1) {second = ++copy; flag = 0;}

    }
    else copy++;
  }

  switch (first[0])
  {
      case '1':
      {
          switch (second[0])
          {
              case '1':{grid[2][3] = '*'; grid[2][4]=third[0]; grid[2][5] = '*'; break;}
              case '2':{grid[2][7] = '*'; grid[2][8]=third[0]; grid[2][9] = '*'; break;}
              case '3':{grid[2][11] = '*';grid[2][12]=third[0];grid[2][13] = '*';break;}
              case '4':{grid[2][15] = '*';grid[2][16]=third[0];grid[2][17] = '*';break;}
              case '5':{grid[2][19] = '*';grid[2][20]=third[0];grid[2][21] = '*';break;}
              case '6':{grid[2][23] = '*';grid[2][24]=third[0];grid[2][25] = '*';break;}
              case '7':{grid[2][27] = '*';grid[2][28]=third[0];grid[2][29] = '*';break;}
              case '8':{grid[2][31] = '*';grid[2][32]=third[0];grid[2][33] = '*';break;}
              case '9':{grid[2][35] = '*';grid[2][36]=third[0];grid[2][37] = '*';break;}
          }
          break;
      }
      case '2':
      {
          switch (second[0])
          {
              case '1':{grid[4][3] = '*'; grid[4][4]=third[0]; grid[4][5] = '*'; break;}
              case '2':{grid[4][7] = '*'; grid[4][8]=third[0]; grid[4][9] = '*'; break;}
              case '3':{grid[4][11] = '*';grid[4][12]=third[0];grid[4][13] = '*';break;}
              case '4':{grid[4][15] = '*';grid[4][16]=third[0];grid[4][17] = '*';break;}
              case '5':{grid[4][19] = '*';grid[4][20]=third[0];grid[4][21] = '*';break;}
              case '6':{grid[4][23] = '*';grid[4][24]=third[0];grid[4][25] = '*';break;}
              case '7':{grid[4][27] = '*';grid[4][28]=third[0];grid[4][29] = '*';break;}
              case '8':{grid[4][31] = '*';grid[4][32]=third[0];grid[4][33] = '*';break;}
              case '9':{grid[4][35] = '*';grid[4][36]=third[0];grid[4][37] = '*';break;}
          }
          break;
      }
      case '3':
      {
          switch (second[0])
          {
              case '1':{grid[6][3] = '*'; grid[6][4]=third[0]; grid[6][5] = '*'; break;}
              case '2':{grid[6][7] = '*'; grid[6][8]=third[0]; grid[6][9] = '*'; break;}
              case '3':{grid[6][11] = '*';grid[6][12]=third[0];grid[6][13] = '*';break;}
              case '4':{grid[6][15] = '*';grid[6][16]=third[0];grid[6][17] = '*';break;}
              case '5':{grid[6][19] = '*';grid[6][20]=third[0];grid[6][21] = '*';break;}
              case '6':{grid[6][23] = '*';grid[6][24]=third[0];grid[6][25] = '*';break;}
              case '7':{grid[6][27] = '*';grid[6][28]=third[0];grid[6][29] = '*';break;}
              case '8':{grid[6][31] = '*';grid[6][32]=third[0];grid[6][33] = '*';break;}
              case '9':{grid[6][35] = '*';grid[6][36]=third[0];grid[6][37] = '*';break;}
          }
          break;
      }
      case '4':
      {
          switch (second[0])
          {
              case '1':{grid[8][3] = '*'; grid[8][4]=third[0]; grid[8][5] = '*'; break;}
              case '2':{grid[8][7] = '*'; grid[8][8]=third[0]; grid[8][9] = '*'; break;}
              case '3':{grid[8][11] = '*';grid[8][12]=third[0];grid[8][13] = '*';break;}
              case '4':{grid[8][15] = '*';grid[8][16]=third[0];grid[8][17] = '*';break;}
              case '5':{grid[8][19] = '*';grid[8][20]=third[0];grid[8][21] = '*';break;}
              case '6':{grid[8][23] = '*';grid[8][24]=third[0];grid[8][25] = '*';break;}
              case '7':{grid[8][27] = '*';grid[8][28]=third[0];grid[8][29] = '*';break;}
              case '8':{grid[8][31] = '*';grid[8][32]=third[0];grid[8][33] = '*';break;}
              case '9':{grid[8][35] = '*';grid[8][36]=third[0];grid[8][37] = '*';break;}
          }
          break;
      }
      case '5':
      {
          switch (second[0])
          {
              case '1':{grid[10][3] = '*'; grid[10][4]=third[0]; grid[10][5] = '*'; break;}
              case '2':{grid[10][7] = '*'; grid[10][8]=third[0]; grid[10][9] = '*'; break;}
              case '3':{grid[10][11] = '*';grid[10][12]=third[0];grid[10][13] = '*';break;}
              case '4':{grid[10][15] = '*';grid[10][16]=third[0];grid[10][17] = '*';break;}
              case '5':{grid[10][19] = '*';grid[10][20]=third[0];grid[10][21] = '*';break;}
              case '6':{grid[10][23] = '*';grid[10][24]=third[0];grid[10][25] = '*';break;}
              case '7':{grid[10][27] = '*';grid[10][28]=third[0];grid[10][29] = '*';break;}
              case '8':{grid[10][31] = '*';grid[10][32]=third[0];grid[10][33] = '*';break;}
              case '9':{grid[10][35] = '*';grid[10][36]=third[0];grid[10][37] = '*';break;}
          }
          break;
      }
      case '6':
      {
          switch (second[0])
          {
              case '1':{grid[12][3] = '*'; grid[12][4]=third[0]; grid[12][5] = '*'; break;}
              case '2':{grid[12][7] = '*'; grid[12][8]=third[0]; grid[12][9] = '*'; break;}
              case '3':{grid[12][11] = '*';grid[12][12]=third[0];grid[12][13] = '*';break;}
              case '4':{grid[12][15] = '*';grid[12][16]=third[0];grid[12][17] = '*';break;}
              case '5':{grid[12][19] = '*';grid[12][20]=third[0];grid[12][21] = '*';break;}
              case '6':{grid[12][23] = '*';grid[12][24]=third[0];grid[12][25] = '*';break;}
              case '7':{grid[12][27] = '*';grid[12][28]=third[0];grid[12][29] = '*';break;}
              case '8':{grid[12][31] = '*';grid[12][32]=third[0];grid[12][33] = '*';break;}
              case '9':{grid[12][35] = '*';grid[12][36]=third[0];grid[12][37] = '*';break;}
          }
          break;
      }
      case '7':
      {
          switch (second[0])
          {
              case '1':{grid[14][3] = '*'; grid[14][4]=third[0]; grid[14][5] = '*'; break;}
              case '2':{grid[14][7] = '*'; grid[14][8]=third[0]; grid[14][9] = '*'; break;}
              case '3':{grid[14][11] = '*';grid[14][12]=third[0];grid[14][13] = '*';break;}
              case '4':{grid[14][15] = '*';grid[14][16]=third[0];grid[14][17] = '*';break;}
              case '5':{grid[14][19] = '*';grid[14][20]=third[0];grid[14][21] = '*';break;}
              case '6':{grid[14][23] = '*';grid[14][24]=third[0];grid[14][25] = '*';break;}
              case '7':{grid[14][27] = '*';grid[14][28]=third[0];grid[14][29] = '*';break;}
              case '8':{grid[14][31] = '*';grid[14][32]=third[0];grid[14][33] = '*';break;}
              case '9':{grid[14][35] = '*';grid[14][36]=third[0];grid[14][37] = '*';break;}
          }
          break;
      }
      case '8':
      {
          switch (second[0])
          {
              case '1':{grid[16][3] = '*'; grid[16][4]=third[0]; grid[16][5] = '*'; break;}
              case '2':{grid[16][7] = '*'; grid[16][8]=third[0]; grid[16][9] = '*'; break;}
              case '3':{grid[16][11] = '*';grid[16][12]=third[0];grid[16][13] = '*';break;}
              case '4':{grid[16][15] = '*';grid[16][16]=third[0];grid[16][17] = '*';break;}
              case '5':{grid[16][19] = '*';grid[16][20]=third[0];grid[16][21] = '*';break;}
              case '6':{grid[16][23] = '*';grid[16][24]=third[0];grid[16][25] = '*';break;}
              case '7':{grid[16][27] = '*';grid[16][28]=third[0];grid[16][29] = '*';break;}
              case '8':{grid[16][31] = '*';grid[16][32]=third[0];grid[16][33] = '*';break;}
              case '9':{grid[16][35] = '*';grid[16][36]=third[0];grid[16][37] = '*';break;}
          }
          break;
      }
      case '9':
      {
          switch (second[0])
          {
              case '1':{grid[18][3] = '*'; grid[18][4]=third[0]; grid[18][5] = '*'; break;}
              case '2':{grid[18][7] = '*'; grid[18][8]=third[0]; grid[18][9] = '*'; break;}
              case '3':{grid[18][11] = '*';grid[18][12]=third[0];grid[18][13] = '*';break;}
              case '4':{grid[18][15] = '*';grid[18][16]=third[0];grid[18][17] = '*';break;}
              case '5':{grid[18][19] = '*';grid[18][20]=third[0];grid[18][21] = '*';break;}
              case '6':{grid[18][23] = '*';grid[18][24]=third[0];grid[18][25] = '*';break;}
              case '7':{grid[18][27] = '*';grid[18][28]=third[0];grid[18][29] = '*';break;}
              case '8':{grid[18][31] = '*';grid[18][32]=third[0];grid[18][33] = '*';break;}
              case '9':{grid[18][35] = '*';grid[18][36]=third[0];grid[18][37] = '*';break;}
          }
          break;
      }
  }
}
display();
}
}
  • 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-22T11:56:01+00:00Added an answer on May 22, 2026 at 11:56 am

    Since printf() buffers, using it as an indicator of exactly what line your segmentation fault occurs on is not generally a good idea. In general, writes to stderr don’t buffer like they do to stdout, so if you are looking to see how far you’ve gotten before a crash, you should do something more like fprintf(stderr, "Got Here before crash...\n");

    That being said, your real problem is in the line

    int check[3] = {atoi(unsolved_str[0]), 0, atoi(unsolved_str[2])};
    

    If you look at your compiler warnings, you should be seeing something like:

    warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast
    /usr/include/stdlib.h:148: note: expected ‘const char *’ but argument is of type ‘char’
    

    You need to re-write that line so that you’re passing constant pointers to char to atoi(), not objects of type char. So try this by adding an address-of operator:

    int check[3] = {atoi(&unsolved_str[0]), 0, atoi(&unsolved_str[2])};
    

    That will now pass the proper pointer type that atoi is expecting.

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

Sidebar

Related Questions

I have a large piece of code, part of whose body contains this piece
Is this piece of code where I lock a part of the function correct?
This piece of code used to work in MVC 1 but it does not
Given this piece of code: (void)someFunction(void) { int array[] = {1,2,3,4,5,6,7,8,9,10}; } Where are
I have this piece of code as part of a socks5 proxy server implementation.
nowadays I have this piece of code: #import C:\Users\Public\SoundLog\DLLs\ForPython\SoundLogDLL.tlb named_guids but I want to
I have this piece of code here below: $fq.= + (fritidsboende_uth_from:[$fritids_uth_from TO *] AND
I'm trying to convert this piece of code from PHP to C#. It's part
I've got this piece of code: using Posix; int fuseguifs_getattr(string path, Posix.Stat *stbuf) {
I have problem running and debugging this piece of code: bool readSectionHeaders(char* path, int

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.