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 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

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3650
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T21:55:55+00:00 2022-06-02T21:55:55+00:00

c – I can’t use char array inside if

  • 0

[ad_1]

Closed. This question needs debugging details. It is not currently accepting answers.


This post was edited and submitted for review 1 hour ago.



When i run my code it runs but it’s return value is not 0. So i tried debugging mode. And the problem is caused by if(yol[i][j]==' ') part. When compiler comes here, segmentation fault error is shown up. Why is this happening guys?

void randomElma(char yol[32][44]){
    srand(time(NULL));
    int i,j;
    for(i=0;i<32;i++){
        for(j=0;j<44;j++){
            if(yol[i][j]==' '){
                if((rand()%10)==1){
                    yol[i][j]='O';
                }
            }
        }
    }
}

Here is my main function:

int main(int argc, char *argv[]) {
    int N=31, M=43;
    int i=0, j=0;
    char ch;
    int map[32][44];
    char yol[32][44];
    puan=0;
    
    FILE *dosya;
    dosya=fopen("harita.txt","r");
    
    while ((ch = fgetc(dosya)) != EOF){
        yol[i][j]=ch;
        if(ch==' ')
            map[i][j]=1;
        else
            map[i][j]=0;
        if(ch=='\n'){
            i++; j=0;
        }
        else{
            j++;
        }
    }
    
    for(i=0;i<31;i++){
        for(j=0;j<44;j++){
            printf("%d",map[i][j]);
        }
        printf("\n");
    }
    fclose(dosya);
    map[29][1]=1;
    map[29][41]=1;
    
    randomElma(yol[32][44]);
    
    DFS(map,29,1,yol); // 29, 41
    
    return 0;
}

Also i added time.h library

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8054 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1842 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1924 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

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.