Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is the problem in this code

+2 votes
asked Sep 10, 2020 by Erald Farrici (160 points)
#include <stdio.h>
#include <conio.h>
int
main ()
{
  int N, i, j;
  char arts[N], muajtS[12];
  float cmime[N];
  printf ("Jepni vleren e N: \n");
  scanf ("%d", &N);
  for (i = 0; i < N; i++)
    {
      printf ("Shenoni artikujt; \n");
      scanf ("%s", &arts[i]);
      printf ("Jepni cmimet e artikujve: \n");
      scanf ("%f", &cmime[i]);

    }
  for (j = 0; j < 12; j++);
  {
    printf ("Jepni muajt:\n");
    scanf ("%s", &muajtS[j]);
    int main()
{
    int trmuaj[12],shuma=0,trvit[i][j];
    for(j=0;j<12;j++){
        shuma=0;
        for(i=0;i<N;i++){
            shuma=shuma+trvit[i][j];
            trmuaj[j]=shuma;}
        
    }
            for(j=0;j<12;j++){
                printf("Per muajn %d xhiroja eshte %d",i,trmuaj[12]);
            }
            int trartikull[N],shuma2;
            for(i=0;i<N;i++){
                shuma2=0;
                for(j=0;j<N;j++){
                    shuma2=shuma2+trvit[i][j];
                    trartikull[i]=shuma2;
                }
            }
            int max1,max2;
            int pozmuaj;
            int pozartikuj;
            max1=trmuaj[0];pozmuaj,pozartikull;
            max2=trartikull[0];
            for(i=0;i<N;i++){
                if(trartikull[1]>max1);
                max1=trartikull[i];
                pozartikull=i;}
                for(j=0;j<12;j++){
                    if(trmuaj[j]>max2);
                    max2=trmuaj[j];
                    pozmuaj=j;
                }
            }
            printf("Muaj me xhiro me te larte eshte muaj: %d",pozmuaj);
            printf("Artikulli me xhiro me te larte eshte: %d",pozartikull);
}
            
 return 0;
    
}

2 Answers

0 votes
answered Sep 11, 2020 by Peter Minarik (84,720 points)
edited Sep 11, 2020 by Peter Minarik

Same problem as this one: http://question.onlinegdb.com/8145/why-i-am-getting-segmentation-fault-core-dumped

  • arts[N]
  • cmime[N]
  • trvit[i][j]
The last one is particularly wrong array definition as while the first 2 would have N set up (and not changed throughout the code, at least in theory), i and j are loop variables and have constantly changing values.

Also, your code is a mesh up between two codes. It has two main() functions. The second starts in the middle of the first one.

Please, sort out what your code should be so one can give it a test run. Also, it's wise to write variables and messages in English, especially if you would like to post it online. It helps the understanding of others who do not speak Albanian.

0 votes
answered Sep 11, 2020 by 0407prince (140 points)

 scanf ("%s", &arts[i]);

scanf ("%s", &muajtS[j]);

You cant specify address to the string,remove '&' from above scanf statements .

commented Sep 14, 2020 by Peter Minarik (84,720 points)
Actually, you can.

The address of any array in C is the array itself.

So the & sign before the array is not needed to get the address, but adding it there is perfectly fine. It's a matter of taste.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...