what is the problem in this code

+2 votes
asked Sep 10 by Erald Farrici (160 points)
#include <stdio.h>
#include <conio.h>
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];
                printf("Per muajn %d xhiroja eshte %d",i,trmuaj[12]);
            int trartikull[N],shuma2;
            int max1,max2;
            int pozmuaj;
            int pozartikuj;
            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 by Peter Minarik (7,830 points)
edited Sep 11 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 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 by Peter Minarik (7,830 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.